var contracts = from c in db.B_Contract_Out
join h in db.B_Hospital on c.HospitalID equals h.ID into ch
where c.C4 == "1" && c.ContractDate < DateTime.Now
from chs in ch.DefaultIfEmpty()
join u in db.sys_User on c.PrincipalUser equals u.UserID into cu
from cus in cu.DefaultIfEmpty()
orderby c.ContractDate descending
join p in db.B_PayRecord on c.ID equals p.ContractID into cp
from cps in cp.DefaultIfEmpty()
where c.AllMoney != Convert.ToDouble(cps.PayMoney)
orderby c.ContractDate descending
//select new { c.WinFee, c.C1, c.BankFee, c.PayType,c.C2,c.Contract,c.Remark, c.ID, c.ContractType, ArmNames = GetArmariumName(c.ID), PayMoney = GetPayedMoney(c.ID), c.CreateTime, c.ArriveDate, c.SetupDate, qiankuan = c.AllMoney - double.Parse(GetPayedMoney(c.ID).ToString()), c.ContractDate, c.ContactNum, cus.U_CName, c.AllMoney, chs.HospitalName };
select new { PayMoney = GetPayedMoney(c.ID), ArmNames = GetArmariumName(c.ID), ArmInPrice = GetArmInPrice(c.ID), USInPrice = GetUSInPrice(c.ID), Duty = GetDuty(Convert.ToDouble(c.AllMoney), c.ID), Profit = GetProfit(Convert.ToDouble(c.AllMoney), c.ID, Convert.ToDouble(c.BankFee), Convert.ToDouble(c.WinFee)), c.WinFee, c.C1, c.BankFee, c.PayType, c.C2, c.Contract, c.Remark, c.ID, c.ContractType, c.CreateTime, c.ArriveDate, c.SetupDate, c.ContractDate, c.ContactNum, cus.U_CName, c.AllMoney, chs.HospitalName, qiankuan = (c.AllMoney - Convert.ToDouble(cps.PayMoney)) };