public static List<HotelDataEntryLib.Helper.Revenue> ListRevenueEntryByMonthYear(HotelRevenue hotelEntry) { var dates = GetLastDayOfMonth(hotelEntry.Month, hotelEntry.Year); var positionMonth = hotelEntry.Month + "/" + hotelEntry.Year; var hdc = new HotelDataEntryDataContext(); var list = (from revenueEntry in hdc.RevenueEntries join hotelRevenue in hdc.HotelRevenues on revenueEntry.HotelRevenueId equals hotelRevenue.HotelRevenueId join hotelBudget in hdc.HotelBudgets on new { hotelRevenue.Year, hotelRevenue.PropertyId } equals new { hotelBudget.Year, hotelBudget.PropertyId } join budgetEntry in hdc.BudgetEntries on hotelBudget.HotelBudgetId equals budgetEntry.HotelBudgetId where revenueEntry.HotelRevenueId == hotelEntry.HotelRevenueId && budgetEntry.PositionMonth == positionMonth orderby revenueEntry.PositionDate select new Revenue() { RevenueId = revenueEntry.RevenueId, PositionDate = revenueEntry.PositionDate, HotelRevenueId = revenueEntry.HotelRevenueId, OccupancyRoom = revenueEntry.OccupancyRoom, RoomRevenue = revenueEntry.RoomRevenue, FBRevenue = revenueEntry.FBRevenue, SpaRevenue = revenueEntry.SpaRevenue, Others = revenueEntry.Others, Total = revenueEntry.Total, Budget = revenueEntry.Total<=0?0:budgetEntry.Total / dates, Day = revenueEntry.PositionDate.DayOfWeek.ToString(), UpdateDateTime = revenueEntry.UpdateDateTime, DateNowMillisecond = DateTime.Now.Ticks, UpdateDateTimeMillisecond = Convert.ToDateTime(revenueEntry.UpdateDateTime).Ticks }).ToList(); return list; }
public static void AddRevenueEntryListByMonthYear(HotelRevenue hotelEntry, string username) { var dates = GetLastDayOfMonth(hotelEntry.Month,hotelEntry.Year); using (var hdc = new HotelDataEntryDataContext()) { for (var i = 0; i < dates; i++) { hdc.RevenueEntries.InsertOnSubmit(new RevenueEntry() { HotelRevenueId = hotelEntry.HotelRevenueId, OccupancyRoom = 0, RoomRevenue = 0.00, FBRevenue = 0.00, SpaRevenue = 0.00, Others = 0.00, Total = 0.00, UpdateDateTime = DateTime.Now, UpdateUser = username, PositionDate = new DateTime(hotelEntry.Year, hotelEntry.Month, (i + 1)) }); try { hdc.SubmitChanges(); } catch (SqlException ex) { if (ex.Number == 2601 || ex.Number == 2627) { throw; } } } } }