public DataTable Query(QueryFullBillServiceForm form) { form.IsDeleted = 0; form.Enabled = 1; return bll.QueryFullBill(form); }
public DataTable QueryFullBill(QueryFullBillServiceForm form) { #region 初始化数据 ISqlMapper mapper = MapperHelper.GetMapper(); BillDao dao = new BillDao(mapper); OtherFeeDao ofbll = new OtherFeeDao(mapper); OtherFeeBillDao ofbbll = new OtherFeeBillDao(mapper); var bills = dao.QueryFullBill(form); var billids = (from b in bills select b.ID).ToList(); var houseids = (from b in bills select b.HouseOrRoomID).ToList(); var otherfee = ofbll.Query(new OtherFeeQueryForm { }); var otherfeebills = ofbbll.Query(new OtherFeeBillQueryForm { BillIDs = billids }); var linkedOtherfeeBills = (from b in otherfeebills join o in otherfee on b.OtherFeeID equals o.ID select new { ID = b.ID, Fee = b.Fee, Name = o.Name, BillID = b.BillID, }).ToList(); #endregion #region 设置字段mapping List<ToDataTableMapping> list = new List<ToDataTableMapping> { new ToDataTableMapping { OrignalName = "Name", MappingName = "账单名称" }, new ToDataTableMapping { OrignalName = "ShouldPay",MappingName = "应收" }, new ToDataTableMapping { OrignalName = "Payed", MappingName = "已收" }, new ToDataTableMapping { OrignalName = "PayDay", MappingName="交租日期" }, new ToDataTableMapping { OrignalName = "HouseOrRoomID", MappingName="房间ID" }, new ToDataTableMapping { OrignalName = "ID", MappingName="ID" }, new ToDataTableMapping { OrignalName = "BuildingName", MappingName="楼栋名称" }, new ToDataTableMapping { OrignalName = "HouseName", MappingName = "房间名称" }, }; #endregion #region 组装数据 DataTable table = bills.ToDataTable(list); foreach (var of in otherfee) { if (!table.Columns.Contains(of.Name)) { DataColumn column = new DataColumn(of.Name, typeof(decimal)); column.DefaultValue = 0; table.Columns.Add(column); } } foreach (DataRow row in table.Rows) { foreach (var ofb in linkedOtherfeeBills) { row[ofb.Name] = ofb.Fee; } } #endregion return table; }