Esempio n. 1
0
        public void SaveDailyRation(DailyRation dailyRation)
        {
            XDocument xdoc       = new XDocument();
            XElement  rationElem = new XElement("Рацион");

            for (int i = 0; i < dailyRation.mealTimes.Count; i++)
            {
                XElement mealElem = new XElement(dailyRation.mealTimes[i].Name);
                for (int j = 0; j < dailyRation.mealTimes[i].products.Count; j++)
                {
                    XElement productElem = new XElement("Продукт",
                                                        new XElement("Имя", dailyRation.mealTimes[i].products[j].Name),
                                                        new XElement("Граммы", dailyRation.mealTimes[i].products[j].Grams),
                                                        new XElement("Белки", dailyRation.mealTimes[i].products[j].Proteins),
                                                        new XElement("Жиры", dailyRation.mealTimes[i].products[j].Fats),
                                                        new XElement("Углеводы", dailyRation.mealTimes[i].products[j].Carbs),
                                                        new XElement("Калории", dailyRation.mealTimes[i].products[j].Calories)
                                                        );
                    mealElem.Add(productElem);
                }
                rationElem.Add(mealElem);
            }
            xdoc.Add(rationElem);
            xdoc.Save("DailyRation.xml");
        }
Esempio n. 2
0
 protected Db(string connectionString)
 {
     if (Db.connectionString == null)
     {
         connectionString = "products.xml";
     }
     else
     {
         Db.connectionString = connectionString;
     }
     Products   = new Dictionary <string, List <Product> >();
     Categories = new List <Category>();
     Ration     = new DailyRation();
     Read(connectionString);
 }
        public void ChangeProductCharacs(DailyRation dailyRation, Product product, int value)
        {
            double calories = product.Calories;
            double grams    = product.Grams;

            for (int i = 0; i < dailyRation.mealTimes.Count; i++)
            {
                for (int j = 0; j < dailyRation.mealTimes[i].products.Count; j++)
                {
                    if (dailyRation.mealTimes[i].products[j].Name == product.Name)
                    {
                        dailyRation.mealTimes[i].products[j].Grams    = value;
                        dailyRation.mealTimes[i].products[j].Calories = (calories * value) / grams;
                    }
                }
            }
        }
Esempio n. 4
0
 public void SaveDailyRation(DailyRation dailyRation)
 {
     dailyRationDao.SaveDailyRation(dailyRation);
 }
Esempio n. 5
0
 public void ChangeProductCharacs(DailyRation dailyRation, Product product, int value)
 {
     productDao.ChangeProductCharacs(dailyRation, product, value);
 }
        public static bool CreatePDF(User user, DailyRation dailyRation)
        {
            if (user == null || dailyRation == null)
            {
                return(false);
            }

            using (PdfDocument document = new PdfDocument())
            {
                PdfPage     page     = document.Pages.Add();
                PdfGraphics graphics = page.Graphics;

                PdfFont titleFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
                PdfFont bigFont   = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
                PdfFont font      = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
                PdfFont smallFont = new PdfStandardFont(PdfFontFamily.Helvetica, 10);

                PdfBrush DarkRedBrush = PdfBrushes.DarkRed;
                PdfBrush BlackBrush   = PdfBrushes.Black;
                PdfPen   darkBluePen  = new PdfPen(Color.DarkBlue, 2);
                PdfPen   darkPenLine  = new PdfPen(Color.Black, 2);

                graphics.DrawString("DAILY RATION", titleFont, DarkRedBrush, new PointF(0, 0));
                graphics.DrawLine(darkPenLine, new PointF(0, 25), new PointF(900, 25));

                graphics.DrawString("INFORMATION", bigFont, BlackBrush, new PointF(0, 60));
                graphics.DrawString("Age: " + user.Age, font, BlackBrush, new PointF(0, 90));
                graphics.DrawString("Height: " + user.Height, font, BlackBrush, new PointF(150, 90));
                graphics.DrawString("Weight: " + user.Weight, font, BlackBrush, new PointF(300, 90));
                graphics.DrawString("Activity: " + user.GetCurrentStringActivity(), font, BlackBrush, new PointF(0, 120));
                graphics.DrawString("ARM: " + user.GetARM(), font, BlackBrush, new PointF(150, 120));
                graphics.DrawString("BMR: " + user.GetBMR(), font, BlackBrush, new PointF(300, 120));
                graphics.DrawString("Need Calories: " + user.GetCalories(), font, DarkRedBrush, new PointF(0, 150));
                graphics.DrawLine(darkPenLine, new PointF(0, 180), new PointF(900, 180));

                graphics.DrawString("DAILY RATION", bigFont, BlackBrush, new PointF(0, 220));
                int line = 220, lineStep = 20;
                foreach (MealTime mealTime in user.DailyRation.MealTimes)
                {
                    if (mealTime.Products.Count == 0)
                    {
                        continue;
                    }

                    line += 40;
                    graphics.DrawString("Meal Time: " + mealTime.Name, font, BlackBrush, new PointF(0, line));
                    DataTable dataTable = new DataTable();
                    PdfGrid   pdfGrid   = new PdfGrid();
                    dataTable.Columns.Add("Name");
                    dataTable.Columns.Add("Gramms");
                    dataTable.Columns.Add("Fats");
                    dataTable.Columns.Add("Carbs");
                    dataTable.Columns.Add("Protein");
                    dataTable.Columns.Add("Calories100");
                    foreach (Product product in mealTime.Products)
                    {
                        dataTable.Rows.Add(new object[]
                        {
                            product.Name,
                            product.Gramms,
                            product.Fats,
                            product.Carbs,
                            product.Protein,
                            product.Calories100
                        });
                    }
                    pdfGrid.DataSource = dataTable;
                    pdfGrid.Draw(page, new PointF(0, line + 20));
                    line += lineStep * mealTime.Products.Count;
                    line += 35;
                    graphics.DrawString("Meal Time TOTAL calories: " + mealTime.GetCalories(), font, DarkRedBrush, new PointF(0, line));
                }
                line += 20;
                graphics.DrawLine(darkPenLine, new PointF(0, line), new PointF(900, line));
                line += 20;
                graphics.DrawString("TOTAL CALORIES: " + dailyRation.GetCalories(), font, DarkRedBrush, new PointF(0, line));

                document.Save(File.Create("DailyRation.pdf"));
                document.Close(true);
                return(false);
            }
        }
Esempio n. 7
0
 public void ExportRation(string sum, string daily_norm, User user, DailyRation ration)
 {
     rationDao.ExportRation(sum, daily_norm, user, ration);
 }
Esempio n. 8
0
 public void DeleteMealTime(DailyRation ration, int index)
 {
     rationDao.DeleteMealTime(ration, index);
 }
Esempio n. 9
0
 public void AddMealTime(MealTime mealTime, DailyRation ration)
 {
     rationDao.AddMealTime(mealTime, ration);
 }
Esempio n. 10
0
        public void ExportRation(string sum, string daily_norm, User user, DailyRation ration)
        {
            XFont small_font = new XFont("sans-serif", 15, XFontStyle.Regular);
            XFont large_font = new XFont("sans-serif", 18, XFontStyle.Regular);
            XFont xlarge_font = new XFont("sans-serif", 25, XFontStyle.Regular);
            int   x = 40, y = 10;

            PdfDocument document = new PdfDocument();

            document.Info.Title = "Мой дневной рацион";
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            gfx.DrawString("Мой дневной рацион",
                           xlarge_font, XBrushes.Black,
                           new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);
            y += 35;
            gfx.DrawString("Информация о пользователе",
                           large_font, XBrushes.Black,
                           new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);
            y += 25;
            gfx.DrawString($"Имя: {user.Name}",
                           small_font, XBrushes.Black,
                           new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 25;
            gfx.DrawString($"Возраст: {user.Age}",
                           small_font, XBrushes.Black,
                           new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 25;
            gfx.DrawString($"Рост: {user.Height}",
                           small_font, XBrushes.Black,
                           new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 25;
            gfx.DrawString($"Вес: {user.Weight}",
                           small_font, XBrushes.Black,
                           new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 25;
            gfx.DrawString($"Тип Активности: {user.ActivityType}",
                           small_font, XBrushes.Black,
                           new XRect(x + 20, y, page.Width, page.Height), XStringFormats.TopLeft);
            y += 30;
            gfx.DrawString($"Рекомендуемая дневная норма: {daily_norm}",
                           xlarge_font, XBrushes.Black,
                           new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);
            foreach (MealTime meal in ration.MealTimes)
            {
                y += 35;
                if (y + 35 > page.Height)
                {
                    page = document.AddPage();
                    gfx  = XGraphics.FromPdfPage(page);
                    y    = 10;
                }
                gfx.DrawString(meal.Name, large_font, XBrushes.Black, new XRect(x, y, page.Width, page.Height), XStringFormats.TopLeft);
                foreach (Product product in meal.mealtimeProducts)
                {
                    y += 25;
                    if (y + 25 > page.Height)
                    {
                        page = document.AddPage();
                        gfx  = XGraphics.FromPdfPage(page);
                        y    = 10;
                    }
                    gfx.DrawString($"{product.Name}: {product.Gramms} грамм",
                                   small_font, XBrushes.Black,
                                   new XRect(x + 25, y, page.Width, page.Height), XStringFormats.TopLeft);
                }
            }
            y += 50;
            if (y > page.Height)
            {
                page = document.AddPage();
                gfx  = XGraphics.FromPdfPage(page);
                y    = 0;
            }
            gfx.DrawString($"Калорийность рациона: {sum}",
                           xlarge_font, XBrushes.Black,
                           new XRect(0, y, page.Width, page.Height), XStringFormats.TopCenter);

            const string filename = "Daily Food Ration.pdf";

            document.Save(filename);
        }
Esempio n. 11
0
 public void DeleteMealTime(DailyRation ration, int index)
 {
     ration.MealTimes.RemoveAt(index);
 }
Esempio n. 12
0
 public void AddMealTime(MealTime mealTime, DailyRation ration)
 {
     ration.MealTimes.Add(mealTime);
 }
Esempio n. 13
0
 public void ClearDailyRation()
 {
     Ration = new DailyRation();
 }