using System;
using System.Collections.Generic;
using System.Linq;

namespace BLL
{
    public static class APIFCLService
    {
        /// <summary>
        /// 获取FC信息列表
        /// </summary>
        /// <param name="foCode">FO编码</param>
        /// <param name="fcStatus">FC状态</param>
        /// <param name="startCreateTime">创建日期起</param>
        /// <param name="endCreateTime">创建日期止</param>
        /// <param name="startUpdateTime">修改日期起</param>
        /// <param name="endUpdateTime">修改日期止</param>
        /// <returns>FC信息列表</returns>
        public static List<Model.FCLItem> GetFCList(string foCode, string fcStatus, DateTime? startCreateTime, DateTime? endCreateTime, DateTime? startUpdateTime, DateTime? endUpdateTime)
        {
            var fcl = from x in Funs.DB.View_FCLAPI select x;
            if (!string.IsNullOrEmpty(foCode))
            {
                fcl = fcl.Where(x => x.Fo_no.Contains(foCode));
            }
            if (!string.IsNullOrEmpty(fcStatus))
            {
                fcl = fcl.Where(x => x.FC_status== fcStatus);
            }
            if (startCreateTime != null)
            {
                fcl = fcl.Where(x => x.CreateDate >= startCreateTime);
            }
            if (endCreateTime != null)
            {
                fcl = fcl.Where(x => x.CreateDate <= endCreateTime);
            }
            if (startUpdateTime != null)
            {
                fcl = fcl.Where(x => x.ModifyDate >= startUpdateTime);
            }
            if (endUpdateTime != null)
            {
                fcl = fcl.Where(x => x.ModifyDate <= endUpdateTime);
            }

            var getFC = (from x in fcl
                               select new Model.FCLItem
                               {
                                   id=x.Id,
                                   createBy = x.CreatePerson,
                                   createTime = x.CreateDate,
                                   updateBy = x.ModifyPerson,
                                   updateTime = x.ModifyDate,
                                   foNo = x.Fo_no,
                                   disciplineFo = x.Discipline_fo,
                                   type = x.Type,
                                   pricingScheme = x.Pricing_scheme,
                                   contractor = x.Contractor,
                                   vendoNo = x.Vendor_no,
                                   item = x.Item,
                                   disciplineCategory = x.Discipline_category,
                                   currency = x.Currency,
                                   materialGroup = x.Material_group,
                                   purchaseGroup = x.Purchase_group,
                                   costElement = x.Cost_element,
                                   serviceType = x.Service_type,
                                   contractAdmin = x.Contract_admin,
                                   costChecker = x.Cost_checker,
                                   buyer = x.Buyer,
                                   mainCoordinator = x.Main_coordinator,
                                   mcDept = x.Mc_dept,
                                   userRepresentative = x.User_representative,
                                   validateDate = x.Validate_date,
                                   expireDate = x.Expire_date,
                                   fcStatus = x.FC_status,
                                   contractPerson = x.Contract_person,
                                   tel = x.Tel,
                                   volumeAllocation = x.Volume_allocation,
                                   contractBudget = x.Contract_budget,
                                   affiliatedTransaction = x.Affiliated_transaction,
                                   checkedValue = x.Checked_value,
                                   remainingBudget = x.Remaining_budget,
                                   remainingBudgetP = x.Remaining_budget_p,
                                   remainingDurationP = x.Remaining_duration_p,
                                   zyhead = x.Zyhead,
                                   zyheadTel = x.Zyhead_tel,
                                   aqhead = x.Aqhead,
                                   aqheadTel = x.Aqhead_tel,
                                   xmjl = x.Xmjl,
                                   xmjlTel = x.Xmjl_tel,
                                   email = x.Email,
                                   constRecords = x.Const_records,
                                   remark = x.Remark,
                                   exceedLimit = x.Exceed_limit
                               }).ToList();

            return getFC;
        }
    }
}