/// <summary>
 /// Create a new MonthlyBill object.
 /// </summary>
 /// <param name="customerId">Initial value of the CustomerId property.</param>
 /// <param name="dateTaken">Initial value of the DateTaken property.</param>
 /// <param name="lunchAmount">Initial value of the LunchAmount property.</param>
 /// <param name="dinnerAmount">Initial value of the DinnerAmount property.</param>
 /// <param name="dailyPayment">Initial value of the DailyPayment property.</param>
 public static MonthlyBill CreateMonthlyBill(global::System.Int32 customerId, global::System.DateTime dateTaken, global::System.Int32 lunchAmount, global::System.Int32 dinnerAmount, global::System.Int32 dailyPayment)
 {
     MonthlyBill monthlyBill = new MonthlyBill();
     monthlyBill.CustomerId = customerId;
     monthlyBill.DateTaken = dateTaken;
     monthlyBill.LunchAmount = lunchAmount;
     monthlyBill.DinnerAmount = dinnerAmount;
     monthlyBill.DailyPayment = dailyPayment;
     return monthlyBill;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the MonthlyBills EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMonthlyBills(MonthlyBill monthlyBill)
 {
     base.AddObject("MonthlyBills", monthlyBill);
 }
Beispiel #3
0
        /// <summary>
        /// Fetches the bill for this month/year. If no such bill exists, then creates a new bill and populates it with default values.
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        private void createMonthlyBill(DateTime startDate, DateTime endDate)
        {
            //If there are no customers in the DB, stop here itself.
            if (db.CustomerDetails.Where(x=>x.isDeleted.Equals("N")).Count() == 0 || selectedCustomerId == -1)
                return;

            //Retrieve this month's bill for this user.
            List<MonthlyBill> thisMonthsBill = retrieveThisUsersBill(startDate, endDate);

            MonthlyBill monthlyBill;

            int month = startDate.Month;
            int year = startDate.Year;
            int noOfDays = DateTime.DaysInMonth(year, month);

            label_billNotSaved.Visible = false;

            //If no records found in the DB, then fill entries manually, according to meal plan of this user.
            if (thisMonthsBill.Count() == 0)
            {
                label_billNotSaved.Visible = true;

                for (int dayNumber = 1; dayNumber <= noOfDays; dayNumber++)
                {
                    monthlyBill = new MonthlyBill();
                    monthlyBill.DateTaken = new DateTime(year, month, dayNumber); //'dayNumber' in the current month.
                    monthlyBill.CustomerId = selectedCustomerId;

                    //Lunch and Dinner initialized to 0 for sundays and saturdays
                    if (monthlyBill.DateTaken.DayOfWeek.Equals(DayOfWeek.Sunday) || monthlyBill.DateTaken.DayOfWeek.Equals(DayOfWeek.Saturday))
                    {
                        monthlyBill.LunchAmount = 0;
                        monthlyBill.DinnerAmount = 0;
                    }
                    else
                    {
                        int lunchOrDinnerId = db.CustomerDetails.Where(x => x.CustomerId == selectedCustomerId && x.isDeleted.Equals("N")).First().LunchOrDinnerId;
                        int mealAmount = db.CustomerDetails.Where(x => x.CustomerId == selectedCustomerId && x.isDeleted.Equals("N")).First().MealPlan.MealAmount;

                        switch (lunchOrDinnerId)
                        {
                            case 0: //Lunch & Dinner
                            {
                                monthlyBill.LunchAmount = mealAmount;
                                monthlyBill.DinnerAmount = mealAmount;
                                break;
                            }
                            case 1: //Lunch Only
                            {
                                monthlyBill.LunchAmount = mealAmount;
                                monthlyBill.DinnerAmount = 0;
                                break;
                            }
                            case 2: //Dinner Only
                            {
                                monthlyBill.LunchAmount = 0;
                                monthlyBill.DinnerAmount = mealAmount;
                                break;
                            }
                            default:
                                break;
                        }
                    }
                    thisMonthsBill.Add(monthlyBill);
                }
            }

            //For Sundays, enter in Comments: Sunday
            foreach (MonthlyBill dailyBill in thisMonthsBill)
            {
                if (dailyBill.DateTaken.DayOfWeek == DayOfWeek.Sunday)
                    dailyBill.Comments = "Sunday";
            }
            dataGridView_billForThisMonth.EditMode = DataGridViewEditMode.EditOnEnter;
            dataGridView_billForThisMonth.DataSource = thisMonthsBill;
            modifyDataGridView();
        }