Ejemplo n.º 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the MealPlans EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMealPlans(MealPlan mealPlan)
 {
     base.AddObject("MealPlans", mealPlan);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Click event of the OkButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void OkButton_Click(object sender, EventArgs e)
        {
            string additionalInfo = this.Form.AdditionalInfoTextBox.Text;
            int count = 0;
            DateTime startDate = this.Form.StartDateTimePicker.Value;
            DateTime endDate = this.Form.EndDateTimePicker.Value.AddSeconds(1.0);
            bool breakfast = this.Form.BreakfastCheckBox.Checked;
            bool diet = this.Form.DietCheckBox.Checked;
            bool dinner = this.Form.DinnerCheckBox.Checked;
            bool lunch = this.Form.LunchCheckBox.Checked;
            bool toRoom = this.Form.ToRoomCheckBox.Checked;
            bool vegetarian = this.Form.VegetarianCheckBox.Checked;

            int.TryParse(this.Form.CountTextBox.Text, out count);

            var visit = DataAccess.Instance.Visits.Single(x => x.Id == this.SecondaryId);

            if ((visit.StartDate > startDate) || (visit.EndDate < endDate))
            {
                MessageBox.Show(
                        "Posiłek nie może znajdować się poza datą wizyty!",
                        "Błąd",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);

                    return;
            }
            if (!dinner && !breakfast && !lunch)
            {
                MessageBox.Show(
                        "Trzeba zaznaczyć posiłki!",
                        "Błąd",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);

                return;
            }

            if ((startDate >= endDate) || count <= 0)
            {
                MessageBox.Show(
                    "Podane wartości nie są prawidłowe lub pozostawiono niewypełnione pola.",
                    "Błąd",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation,
                    MessageBoxDefaultButton.Button1);

                return;
            }

            double price = 0;
            var mealPrice = DataAccess.Instance.MealPrices.GetAll().FirstOrDefault();
            if (dinner && breakfast && lunch)
            {
                price = mealPrice.ThreeMealsPrice;
            }
            else
            {
                if (dinner)
                {
                    price += mealPrice.DinnerPrice;
                }

                if (breakfast)
                {
                    price += mealPrice.BreakfastPrice;
                }

                if (lunch)
                {
                    price += mealPrice.LunchPrice;
                }
            }

            price *= count;
            price *= endDate.Subtract(startDate).Days + 1;
            if (this.IsEditForm)
            {
                this.visitMealPlan.MealPlan.PeopleCount = count;
                this.visitMealPlan.MealPlan.Diet = diet;
                this.visitMealPlan.MealPlan.Breakfast = breakfast;
                this.visitMealPlan.MealPlan.Dinner = dinner;
                this.visitMealPlan.MealPlan.Lunch = lunch;
                this.visitMealPlan.MealPlan.ToRoom = toRoom;
                this.visitMealPlan.MealPlan.Vegetarian = vegetarian;
                this.visitMealPlan.MealPlan.Price = price;
                this.visitMealPlan.StartDate = startDate;
                this.visitMealPlan.EndDate = endDate;
                this.visitMealPlan.MealPlan.AdditionalInfo = additionalInfo;
            }
            else
            {
                var mealPlan = new MealPlan
                    {
                        AdditionalInfo = additionalInfo,
                        Breakfast = breakfast,
                        Diet = diet,
                        Dinner = dinner,
                        Lunch = lunch,
                        PeopleCount = count,
                        Price = price,
                        ToRoom = toRoom,
                        Vegetarian = vegetarian
                    };
                DataAccess.Instance.MealPlans.Add(mealPlan);
                DataAccess.Instance.UnitOfWork.Commit();
                this.visitMealPlan = new VisitMealPlan
                {
                    StartDate = startDate,
                    EndDate = endDate,
                    MealPlan = mealPlan,
                    VisitId = this.SecondaryId
                };

                DataAccess.Instance.VisitMealPlans.Add(this.visitMealPlan);
            }

            DataAccess.Instance.UnitOfWork.Commit();

            this.Form.Dispose();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new MealPlan object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="peopleCount">Initial value of the PeopleCount property.</param>
 /// <param name="breakfast">Initial value of the Breakfast property.</param>
 /// <param name="lunch">Initial value of the Lunch property.</param>
 /// <param name="dinner">Initial value of the Dinner property.</param>
 /// <param name="vegetarian">Initial value of the Vegetarian property.</param>
 /// <param name="diet">Initial value of the Diet property.</param>
 /// <param name="toRoom">Initial value of the ToRoom property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static MealPlan CreateMealPlan(global::System.Int32 id, global::System.Int32 peopleCount, global::System.Boolean breakfast, global::System.Boolean lunch, global::System.Boolean dinner, global::System.Boolean vegetarian, global::System.Boolean diet, global::System.Boolean toRoom, global::System.Double price)
 {
     MealPlan mealPlan = new MealPlan();
     mealPlan.Id = id;
     mealPlan.PeopleCount = peopleCount;
     mealPlan.Breakfast = breakfast;
     mealPlan.Lunch = lunch;
     mealPlan.Dinner = dinner;
     mealPlan.Vegetarian = vegetarian;
     mealPlan.Diet = diet;
     mealPlan.ToRoom = toRoom;
     mealPlan.Price = price;
     return mealPlan;
 }