using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace BLL
{
    public class HseCostCService
    {
        public static Model.SGGLDB db = Funs.DB;
        /// 
        /// 获取分页列表
        /// 
        /// 
        public static IEnumerable getListData(string monthReportId)
        {
            return from x in db.Manager_HseCostC
                   where x.MonthReportId == monthReportId
                   orderby x.UnitId
                   select new
                   {
                       UnitName = (from y in db.Base_Unit where y.UnitId == x.UnitId select y.UnitName).First(),
                       x.PlanCost,
                       x.RealCost,
                       x.TotalRealCost//=string.Format("{0:N2}",x.TotalRealCost)              
                   };
        }
        /// 
        /// 根据月报告主键获取所有月报告HSE技术措施费用信息
        /// 
        /// 月报告主键
        /// 
        public static List GetHseCostsByMonthReportId(string monthReportId)
        {
            return (from x in Funs.DB.Manager_HseCostC where x.MonthReportId == monthReportId orderby x.UnitId select x).ToList();
        }
        /// 
        /// 根据月报告主键获取总累计实际支出
        /// 
        /// 单位主键
        /// 月报告主键
        /// 
        public static decimal? GetSumTotalRealCostByMonthReportId(string monthReportId, string unitId)
        {
            return (from x in Funs.DB.Manager_HseCostC where x.MonthReportId == monthReportId && x.UnitId == unitId select x.TotalRealCost).FirstOrDefault();
        }
        /// 
        /// 增加月报告HSE技术措施费用信息
        /// 
        /// 月报告HSE技术措施费用实体
        public static void AddHseCost(Model.Manager_HseCostC hseCost)
        {
            Model.SGGLDB db = Funs.DB;
            string newKeyID = SQLHelper.GetNewID(typeof(Model.Manager_HseCostC));
            Model.Manager_HseCostC newHseCost = new Model.Manager_HseCostC
            {
                HseCostId = newKeyID,
                MonthReportId = hseCost.MonthReportId,
                UnitId = hseCost.UnitId,
                PlanCost = hseCost.PlanCost,
                RealCost = hseCost.RealCost,
                TotalRealCost = hseCost.TotalRealCost
            };
            db.Manager_HseCostC.InsertOnSubmit(newHseCost);
            db.SubmitChanges();
        }
        /// 
        /// 根据月报告主键删除对应的所有月报告HSE技术措施费用信息
        /// 
        /// 月报告主键
        public static void DeleteHseCostsByMonthReportId(string monthReportId)
        {
            var q = (from x in db.Manager_HseCostC where x.MonthReportId == monthReportId select x).ToList();
            if (q.Count>0)
            {
                db.Manager_HseCostC.DeleteAllOnSubmit(q);
                db.SubmitChanges();
            }
        }
    }
}