252 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			252 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								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;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace BLL
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public static class WbsDetailService
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据Id获取一个WBS明细信息
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="wbsDetailId">WBS明细Id</param>
							 | 
						|||
| 
								 | 
							
								        public static Model.WbsDetail GetWbsDetailByWbsDetailId(string wbsDetailId)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return Funs.DB.WbsDetail.FirstOrDefault(e => e.WbsDetailId == wbsDetailId);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据ToWbs判断是否存在WBS明细信息
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="toWbs">toWbs</param>
							 | 
						|||
| 
								 | 
							
								        public static bool IsExitWbsDetailByToWbs(string toWbs)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return (from x in Funs.DB.WbsDetail where x.ToWbs == toWbs select x).Count() > 0;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据toWbs和toFlag和年及月获取对应WBS明细信息
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="toWbs">对应wbsId</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="toFlag">对应标志</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="years">年</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="months">月</param>
							 | 
						|||
| 
								 | 
							
								        public static Model.WbsDetail GetWbsDetailByWbsFlagYearMonth(string toWbs, int toFlag, DateTime months)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return (from x in Funs.DB.WbsDetail where x.ToWbs == toWbs && x.ToFlag == toFlag && x.Months == months select x).FirstOrDefault();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public static Model.WbsDetail GetWbsDetailByToWbsFlag(string toWbs, int toFlag)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return (from x in Funs.DB.WbsDetail where x.ToWbs == toWbs && x.ToFlag == toFlag select x).FirstOrDefault();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据ToWbs和月份判断是否存在未审核WBS明细信息
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="toWbs">toWbs</param>
							 | 
						|||
| 
								 | 
							
								        public static bool IsExitNoCompleteApproveWbsDetailByToWbs(string toWbs, int toFlag, DateTime months)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            bool result;
							 | 
						|||
| 
								 | 
							
								            var q = Funs.DB.WbsDetail.FirstOrDefault(e => e.ToWbs == toWbs && e.ToFlag == toFlag && e.Months == months);
							 | 
						|||
| 
								 | 
							
								            if (q != null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                if (q.IsCompleteApprove == null && (q.CompleteValue != null || q.RealValue != null))
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    result = true;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    result = false;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            else
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                result = false;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            return result;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="toWbs"></param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="toFlag"></param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="months"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public static bool IsExitWbsDetailByToWbsOrMonth(string toWbs, int toFlag, DateTime months)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            bool result = false;
							 | 
						|||
| 
								 | 
							
								            var q = Funs.DB.WbsDetail.FirstOrDefault(e => e.ToWbs == toWbs && e.ToFlag == toFlag && e.Months == months);
							 | 
						|||
| 
								 | 
							
								            if (q != null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                result = true;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            return result;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据年及月获取之前月份的对应WBS明细信息集合(含当月)
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="years">年</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="months">月</param>
							 | 
						|||
| 
								 | 
							
								        public static List<Model.WbsDetail> GetTotalWbsDetailsByYearMonth2(string toWbs, DateTime months)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return (from x in Funs.DB.WbsDetail where x.ToWbs == toWbs && x.Months <= months select x).ToList();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据ToWbs月获取所有月份的对应WBS明细信息集合
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="toWbs">toWbs</param>
							 | 
						|||
| 
								 | 
							
								        public static List<Model.WbsDetail> GetTotalWbsDetailsByToWbs(string toWbs)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return (from x in Funs.DB.WbsDetail where x.ToWbs == toWbs orderby x.Months select x).ToList();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据年及月获取之前月份的对应WBS明细信息集合(含当月)
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="years">年</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="months">月</param>
							 | 
						|||
| 
								 | 
							
								        public static List<Model.WbsDetail> GetTotalWbsDetailsByYearMonth(string toWbs, int toFlag, DateTime months)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return (from x in Funs.DB.WbsDetail where x.ToWbs == toWbs && x.ToFlag == toFlag && x.Months <= months select x).ToList();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 增加WBS明细
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="user">WBS明细</param>
							 | 
						|||
| 
								 | 
							
								        public static void AddWbsDetail(Model.WbsDetail wbsDetail)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Model.SGGLDB db = Funs.DB;
							 | 
						|||
| 
								 | 
							
								            Model.WbsDetail newWbsDetail = new Model.WbsDetail();
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.WbsDetailId = wbsDetail.WbsDetailId;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.ToWbs = wbsDetail.ToWbs;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.ToFlag = wbsDetail.ToFlag;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.Way = wbsDetail.Way;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.Months = wbsDetail.Months;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.EngineeringQuantity = wbsDetail.EngineeringQuantity;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.PlanValue = wbsDetail.PlanValue;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.PlanValueRate = wbsDetail.PlanValueRate;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.CompleteValue = wbsDetail.CompleteValue;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.CompleteValueRate = wbsDetail.CompleteValueRate;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.RealValue = wbsDetail.RealValue;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.RealValueRate = wbsDetail.RealValueRate;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            db.WbsDetail.InsertOnSubmit(newWbsDetail);
							 | 
						|||
| 
								 | 
							
								            db.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 修改WBS明细
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="user">WBS明细</param>
							 | 
						|||
| 
								 | 
							
								        public static void UpdateWbsDetail(Model.WbsDetail wbsDetail)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Model.SGGLDB db = Funs.DB;
							 | 
						|||
| 
								 | 
							
								            Model.WbsDetail newWbsDetail = db.WbsDetail.First(e => e.WbsDetailId == wbsDetail.WbsDetailId);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.EngineeringQuantity = wbsDetail.EngineeringQuantity;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.PlanValue = wbsDetail.PlanValue;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.PlanValueRate = wbsDetail.PlanValueRate;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.CompleteValue = wbsDetail.CompleteValue;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.CompleteValueRate = wbsDetail.CompleteValueRate;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.RealValue = wbsDetail.RealValue;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.RealValueRate = wbsDetail.RealValueRate;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.IsCompleteApprove = wbsDetail.IsCompleteApprove;
							 | 
						|||
| 
								 | 
							
								            newWbsDetail.IsRealApprove = wbsDetail.IsRealApprove;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            db.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据Id删除WBS明细信息
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="userId"></param>
							 | 
						|||
| 
								 | 
							
								        public static void DeleteWbsDetail(string wbsDetailId)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Model.SGGLDB db = Funs.DB;
							 | 
						|||
| 
								 | 
							
								            Model.WbsDetail ins = db.WbsDetail.First(e => e.WbsDetailId == wbsDetailId);
							 | 
						|||
| 
								 | 
							
								            db.WbsDetail.DeleteOnSubmit(ins);
							 | 
						|||
| 
								 | 
							
								            db.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据toWbs删除WBS明细信息
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="userId"></param>
							 | 
						|||
| 
								 | 
							
								        public static void DeleteWbsDetailByToWbs(string toWbs)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Model.SGGLDB db = Funs.DB;
							 | 
						|||
| 
								 | 
							
								            var details = from x in db.WbsDetail where x.ToWbs == toWbs select x;
							 | 
						|||
| 
								 | 
							
								            if (details.Count() > 0)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                db.WbsDetail.DeleteAllOnSubmit(details);
							 | 
						|||
| 
								 | 
							
								                db.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据月份总数和当前是第几月及总计划费用获取当前月份的计划值
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="monthCount">月份总数</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="monthNum">当前是第几月</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="weightMoney">总计划费用</param>
							 | 
						|||
| 
								 | 
							
								        /// <returns>当前月份的计划值</returns>
							 | 
						|||
| 
								 | 
							
								        public static decimal GetMonthPlanValueByMonthCountAndMonthNumAndWeightMonth(int monthCount, int monthNum, decimal weightMoney)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            decimal monthValue = 0;
							 | 
						|||
| 
								 | 
							
								            int halfLevelCount = 0;    //一半的阶级总数,比如12个月,则一半共有21个阶级,共21X
							 | 
						|||
| 
								 | 
							
								            int levelCount = 0;     //总共有多少阶级,比如12个月,则共有42个阶级,共42X
							 | 
						|||
| 
								 | 
							
								            int count = 0;          //阶级绝对数,比如12个月,则共分为6个阶级,1X,2X,3X,4X,5X,6X
							 | 
						|||
| 
								 | 
							
								            decimal oneValue = 0;     //每一阶级即X的值
							 | 
						|||
| 
								 | 
							
								            if (monthCount % 2 == 0)   //月份总数为偶数
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                count = monthCount / 2;
							 | 
						|||
| 
								 | 
							
								                for (int i = 1; i < count + 1; i++)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    halfLevelCount += i;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                levelCount = halfLevelCount * 2;
							 | 
						|||
| 
								 | 
							
								                //oneValue = decimal.Round(Convert.ToDecimal(weightMoney / levelCount), 2);
							 | 
						|||
| 
								 | 
							
								                oneValue = decimal.Round(Convert.ToDecimal(Math.Floor((weightMoney * 100) / levelCount) / 100), 2);//不进行四舍五入
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                if (monthNum > count)    //当前月份大于中间的月份,比如12个月,当前为第8月,则阶级为5X
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    monthNum = monthCount - monthNum + 1;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                monthValue = monthNum * oneValue;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            else    //月份总数为奇数
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                count = (monthCount - 1) / 2;
							 | 
						|||
| 
								 | 
							
								                for (int i = 1; i < count + 1; i++)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    halfLevelCount += i;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                levelCount = halfLevelCount * 2 + (count + 1);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                //oneValue = decimal.Round(Convert.ToDecimal(weightMoney / levelCount), 2);
							 | 
						|||
| 
								 | 
							
								                oneValue = decimal.Round(Convert.ToDecimal(Math.Floor((weightMoney * 100) / levelCount) / 100), 2);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                if (monthNum > (count + 1))    //当前月份大于中间的月份,比如13个月,当前为第8月,则阶级为6X
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    monthNum = monthCount - monthNum + 1;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                monthValue = monthNum * oneValue;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            return monthValue;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |