예제 #1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string fnev = ABKezelo.GetCurrentUser();
                int    i, j, k;
                int    p = 0, q = 0;
                for (i = 0; i < 2; i++)
                {
                    for (j = 0; j < 4; j++)
                    {
                        for (k = 0; k < 2; k++)
                        {
                            EtkezesFeltetel etk = new EtkezesFeltetel(fnev, (ElelmiszerTipus2)i, (EtkezesTipus2)j,
                                                                      (Szamlalo)k, (double)numericUpDowns[p].Value, checkBoxs[q].Checked,
                                                                      (double)numericUpDowns[p + 1].Value);
                            p += 2;
                            q++;
                            ABKezelo.Torol(etk);
                            ABKezelo.Beszuras(etk);
                        }
                    }
                }

                EtrendIdopont et = new EtrendIdopont(fnev, new List <DateTime>(3));
                for (i = 0; i < 3; i++)
                {
                    et.Datum.Add(new DateTime(2018, 1, 1, (int)numericUpDowns2[2 * i].Value,
                                              (int)numericUpDowns2[2 * i + 1].Value, 0));
                }

                if (ABKezelo.Kiolvasas().Where(x => x is EtrendIdopont).ToList().Count > 0)
                {
                    ABKezelo.Modositas(et);
                }
                else
                {
                    ABKezelo.Beszuras(et);
                }
                Logolas.Ment("Saved diet conditions.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
파일: Naptar.cs 프로젝트: gerbicz/MenuMaker
        public static void NaptarbaRak()
        {
            try
            {
                UserCredential credential;

                using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
                {
                    string credPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                }

                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });

                Event evnt = new Event();

                EtrendFeltetel e = (EtrendFeltetel)ABKezelo.Kiolvasas().Where(x => x is EtrendFeltetel).First();

                var l = ABKezelo.Kiolvasas().Where(x => x is EtrendElelmiszer).ToList();

                DateTime e1 = e.Datum1;
                DateTime e2 = e.Datum2;
                e1 = new DateTime(e1.Year, e1.Month, e1.Day, 0, 0, 0);
                e2 = new DateTime(e2.Year, e2.Month, e2.Day, 0, 0, 0);
                DateTime d = e1;

                int[] ido = new int[3];

                var v = ABKezelo.Kiolvasas().Where(x => x is EtrendIdopont).ToList();
                if (v.Count > 0)
                {
                    EtrendIdopont et = (EtrendIdopont)v.First();
                    for (int i = 0; i < 3; i++)
                    {
                        ido[i] = 60 * et.Datum[i].Hour + et.Datum[i].Minute;
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        ido[i] = 60 * (7 + 6 * i) + 30;
                    }
                }

                int num = 0;
                while (d <= e2)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (d == e1 && i < (int)e.Etkezes1)
                        {
                            continue;
                        }
                        if (d == e2 && i > (int)e.Etkezes2)
                        {
                            continue;
                        }

                        var l2 = l.Where(x =>
                                         (x as EtrendElelmiszer).Datum == d && (int)(x as EtrendElelmiszer).Etkezes == i).ToList();

                        string str = ((EtkezesTipus)i).ToString() + ":";
                        foreach (EtrendElelmiszer item in l2)
                        {
                            Elelmiszer elelmiszer = item.Elelmiszer;
                            if (elelmiszer is Etel)
                            {
                                str += String.Format("{0:0.0} {1} {2};", item.Tomeg, item.Tomegmertekegyseg.Megnevezes,
                                                     elelmiszer.Megnevezes);
                            }
                            else if (elelmiszer is Ital)
                            {
                                str += String.Format("{0:0.0} {1} {2};", item.Urmertek, item.Urmertekegyseg.Megnevezes,
                                                     elelmiszer.Megnevezes);
                            }
                            else
                            {
                                str += String.Format("{0:0.0} {1} [{2:0.0} {3}, {4:0.0} {5}];", item.Val,
                                                     elelmiszer.Megnevezes, item.Tomeg,
                                                     item.Tomegmertekegyseg.Megnevezes, item.Urmertek, item.Urmertekegyseg.Megnevezes);
                            }
                        }

                        evnt.Summary     = str;
                        evnt.Description = ((EtkezesTipus)i).ToString();

                        DateTime d1 = d + TimeSpan.FromMinutes(ido[i]);
                        DateTime d2 = d1 + TimeSpan.FromMinutes(30); //30 perc hosszú étkezés

                        // időpontok beállitása
                        evnt.Start = new EventDateTime()
                        {
                            DateTime = d1
                        };
                        evnt.End = new EventDateTime()
                        {
                            DateTime = d2
                        };

                        String calendarId = "primary";
                        service.Events.Insert(evnt, calendarId).Execute();
                    }

                    d = d.AddDays(1);
                }
                Logolas.Ment("Successful save to calendar");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        public EtrendBeallitForm()
        {
            try
            {
                InitializeComponent();
                VezerlokLetrehozasa();
                AddButtonClick();
                var e = ABKezelo.Kiolvasas().Where(x => x is EtkezesFeltetel).ToList();

                int i, j, k;
                for (i = 0; i < 2; i++)
                {
                    for (j = 0; j < 4; j++)
                    {
                        for (k = 0; k < 2; k++)
                        {
                            if (e.Where(x => i == (int)(x as EtkezesFeltetel).Eltipus2 &&
                                        j == (int)(x as EtkezesFeltetel).Ettipus2 &&
                                        k == (int)(x as EtkezesFeltetel).Szamlalo).Count() > 0)
                            {
                                var e0 = e.Where(x =>
                                                 i == (int)(x as EtkezesFeltetel).Eltipus2 &&
                                                 j == (int)(x as EtkezesFeltetel).Ettipus2 &&
                                                 k == (int)(x as EtkezesFeltetel).Szamlalo).First();

                                double v1 = (e0 as EtkezesFeltetel).Minval;
                                bool   c  = (e0 as EtkezesFeltetel).MaxvalE;
                                double v2 = (e0 as EtkezesFeltetel).Maxval;

                                int pos = 8 * i + 2 * j + k;
                                checkBoxs[pos].Checked = c;
                                if (k == 1)
                                {
                                    numericUpDowns[2 * pos].Value     = (decimal)v1;
                                    numericUpDowns[2 * pos + 1].Value = (decimal)v2;
                                }
                                else
                                {
                                    numericUpDowns[2 * pos].Value     = (int)v1;
                                    numericUpDowns[2 * pos + 1].Value = (int)v2;
                                }
                            }
                        }
                    }
                }

                e = ABKezelo.Kiolvasas().Where(x => x is EtrendIdopont).ToList();

                if (e.Count > 0)
                {
                    EtrendIdopont et = (EtrendIdopont)e.First();
                    for (i = 0; i < 3; i++)
                    {
                        numericUpDowns2[2 * i].Value     = et.Datum[i].Hour;
                        numericUpDowns2[2 * i + 1].Value = et.Datum[i].Minute;
                    }
                }
                else
                {
                    for (i = 0; i < 3; i++)
                    {
                        // 7.30; 13.30; 19.30
                        numericUpDowns2[2 * i].Value     = 7 + 6 * i;
                        numericUpDowns2[2 * i + 1].Value = 30;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }