Exemple #1
0
 private void button4_Click(object sender, EventArgs e)
 {
     OtherFeeBLL bll = new OtherFeeBLL();
     var result = bll.Query(new OtherFeeQueryForm { Enabled = 1, IsDeleted = 0 });
 }
Exemple #2
0
        public int GenerateBill(string userid)
        {
            #region init data
            var now = DateTime.Now;
            var premonth = DateTime.Now.AddMonths(-1);
            HouseBLL housebll = new HouseBLL();
            RentFeeBLL rentfeebll = new RentFeeBLL();
            OtherFeeBLL otherfeebll = new OtherFeeBLL();
            House_OtherFeeBLL hobll = new House_OtherFeeBLL();
            OtherFeeBillBLL ofbbll = new OtherFeeBillBLL();
            var houses = housebll.Query(new HouseQueryForm { IsDeleted = 0, Enabled = 1, IsOurs = 1 });
            var houseids = (from h in houses select h.ID).ToList();
            var rentfees = rentfeebll.Query(new RentFeeQueryForm { Enabled = 1, IsDeleted = 0, RentDay_Start = 1, RentDay_End = now.Day, ExpiredTime_Start = now });
            var premonthbills = Query(new BillQueryForm { Year = premonth.Year, Month = premonth.Month, HouseOrRoomIDs = houseids });
            var currentmonethbill = Query(new BillQueryForm { Year = now.Year, Month = now.Month, HouseOrRoomIDs = houseids });
            var otherfee = otherfeebll.Query(new OtherFeeQueryForm { });
            var ho = hobll.Query(new House_OtherFeeQueryForm { HouseOrRoomIDs = houseids });
            var premonthbillids = (from b in premonthbills select b.ID).ToList();
            var premonthofb = ofbbll.Query(new OtherFeeBillQueryForm { BillIDs = premonthbillids });
            var linked_ho = (from h in ho
                             join of in otherfee on h.OtherFeeID equals of.ID
                             select new { House_OtherFee = h, Fee = of }).ToList();
            #endregion

            #region 生成当日和当日之前未生成的账单
            int i = 0;
            foreach (var rentfee in rentfees)
            {
                //如果存在就说明已经生成过了,这条房租账单不生成
                if (currentmonethbill.Exists(t => t.HouseOrRoomID.Equals(rentfee.HouseOrRoomID))) continue;
                var billid = Guid.NewGuid().ToString().Replace("-", "");
                Bill bill = new Bill
                {
                    ID = billid,
                    HouseOrRoomID = rentfee.HouseOrRoomID,
                    PayDay = new DateTime(now.Year, now.Month, rentfee.RentDay.Value),
                    Month = now.Month,
                    Year = now.Year,
                    Type = rentfee.Type,
                    Creator = userid,
                    ShouldPay = rentfee.RentMoney,
                    Name = now.ToString("yyyyMM月账单"),

                };
                var house_otherfees = linked_ho.FindAll(t => t.House_OtherFee.HouseOrRoomID.Equals(rentfee.HouseOrRoomID));
                var premonthbill = premonthbills.Find(t => t.Year == premonth.Year && t.Month == premonth.Month);
                //生成其他费用账单
                foreach (var house_otherfee in house_otherfees)
                {
                    OtherFeeBill data = new OtherFeeBill
                    {
                        BillID = bill.ID,
                        OtherFeeID = house_otherfee.Fee.ID,
                        Name = house_otherfee.Fee.Name,
                        Creator = userid,
                        Fee = 0,
                        EndValue = 0,
                        StartValue = 0,
                    };
                    //把本月起始的计数设置为上月结束的计数
                    if (premonthbill != null) data.StartValue = premonthofb.Find(t => t.BillID.Equals(premonthbill.ID))?.EndValue;
                    ofbbll.Add(data);
                }
                Add(bill);
                i++;
            }
            #endregion
            return i;
        }