Exemple #1
0
 private void btnLog_Click(object sender, EventArgs e)
 {
     using (DomowyFastFoodContext Context = new DomowyFastFoodContext())
     {
         if (Context.Klients.AsParallel().Where(x => x.Nick == txtBoxLogin.Text).Count() > 0 &&
             Context.Klients.AsParallel().Where(x => x.Password == txtBoxPassword.Text).Count() > 0)
         {
             Identity = txtBoxLogin.Text;
             frmUserControlPanel f = new frmUserControlPanel(Identity);
             f.ShowDialog();
         }
         else if (Context.Pracowniks.AsParallel().Where(x => x.Nick == txtBoxLogin.Text).Count() > 0 &&
                  Context.Pracowniks.AsParallel().Where(x => x.Password == txtBoxPassword.Text).Count() > 0)
         {
             Authorization = Context.Pracowniks.AsParallel().Where(x => x.Nick == txtBoxLogin.Text).FirstOrDefault().Autoryzacja;
             Identity      = txtBoxLogin.Text;
             frmAdminControlPanel f = new frmAdminControlPanel(Authorization, Identity);
             f.ShowDialog();
         }
         else
         {
             MessageBox.Show("Błąd Logowania", "Niepoprawny login lub hasło", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        private void btnDelOrder_Click(object sender, EventArgs e)
        {
            var id = int.Parse(dgvOrder.Rows[dgvOrder.SelectedCells[0].RowIndex].Cells[0].Value.ToString());

            using (var Context = new DomowyFastFoodContext())
            {
                var removeOrder = Context
                                  .Zamowienies
                                  .FirstOrDefault(x => x.ID_Zamowienia == id);
                var removeCommand = Context
                                    .Entry(removeOrder);
                removeCommand.State = EntityState.Deleted;
                Context.SaveChanges();
            }
            this.OnLoad(e);
        }
        private void btnOrder_Click(object sender, EventArgs e)
        {
            using (DomowyFastFoodContext Context = new DomowyFastFoodContext())
            {
                var client = Context.Klients.SingleOrDefault(x => x.Nick == Identity);
                var id     = client.ID_Klienta;
                var idRes  = int.Parse(dgvRestaurant.Rows[dgvRestaurant.SelectedCells[0].RowIndex].Cells[0].Value.ToString());
                var Dinner = Context.Restauracjas.SingleOrDefault(x => x.ID_Restauracji == idRes);

                Context.Zamowienies.Add(new Zamowienie
                {
                    ID_Zamowienia  = Context.Zamowienies.Max(x => x.ID_Zamowienia) + 1,
                    ID_Klienta     = id,
                    ID_Restauracji = idRes,
                    DanieDnia      = Dinner.DanieDnia,
                    DataZamowienia = DateTime.Now.Date
                });
                Context.SaveChanges();
                MessageBox.Show("Pomyslnie dodano zamowienie", "Zamow!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #4
0
 private void btnRegister_Click(object sender, EventArgs e)
 {
     try
     {
         using (DomowyFastFoodContext Context = new DomowyFastFoodContext())
         {
             Context.Klients.Add(new Klient
             {
                 ID_Klienta = Context.Klients.Max(x => x.ID_Klienta) + 1,
                 Nick       = txtboxNick.Text,
                 Password   = txtboxPassword.Text,
                 Adres      = txtboxAdress.Text,
                 Telefon    = txtboxPhone.Text
             });
             Context.SaveChanges();
             Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
         throw;
     }
 }
        private void frmAdminControlPanel_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ID_Zamowienia");
            dt.Columns.Add("Pracownik");
            dt.Columns.Add("Telefon Pracownika");
            dt.Columns.Add("Nazwa Restauracji");
            dt.Columns.Add("Danie Dnia");
            dt.Columns.Add("Telefon Restauracji");
            dt.Columns.Add("Data Zamowienia");
            dt.AcceptChanges();



            using (var Context = new DomowyFastFoodContext())
            {
                var clientDatav2 = Context.Zamowienies                                                     // your starting point - table in the "from" statement
                                   .Join(Context.Klients,                                                  // the source table of the inner join
                                         zam => zam.ID_Klienta,                                            // Select the primary key (the first part of the "on" clause in an sql "join" statement)
                                         client => client.ID_Klienta,                                      // Select the foreign key (the second part of the "on" clause)
                                         (zam, client) => new { Zam = zam, Client = client })              // selection
                                   .Where(x => x.Zam.ID_Klienta == x.Client.ID_Klienta)
                                   .Join(Context.Restauracjas,                                             // the source table of the inner join
                                         zam => zam.Zam.ID_Restauracji,                                    // Select the primary key (the first part of the "on" clause in an sql "join" statement)
                                         restaurant => restaurant.ID_Restauracji,                          // Select the foreign key (the second part of the "on" clause)
                                         (zam, restaurant) => new { Zam2 = zam, Restaurant = restaurant }) // selection
                                   .Where(x => x.Zam2.Zam.ID_Restauracji == x.Restaurant.ID_Restauracji);


                var filteredClientDatav2   = clientDatav2.AsParallel().Select(x => new { x.Zam2.Zam.ID_Zamowienia, x.Zam2.Client.Nick, x.Zam2.Client.Telefon, x.Restaurant.NazwaRestauracji, x.Zam2.Zam.DanieDnia, x.Zam2.Zam.DataZamowienia }).ToList();
                var filteredRestaurantdata = clientDatav2.AsParallel().Select(x => x.Restaurant.Telefon).ToList();
                var orderDate = Context.Zamowienies.Select(x => x.DataZamowienia).ToList();

                foreach (var item in filteredClientDatav2.Zip(filteredRestaurantdata, Tuple.Create))
                {
                    dt.Rows.Add(item.Item1.ID_Zamowienia, item.Item1.Nick, item.Item1.Telefon, item.Item1.NazwaRestauracji, item.Item1.DanieDnia, item.Item2, item.Item1.DataZamowienia);
                }
                dt.AcceptChanges();
                dgvOrder.DataSource = dt;
                //     // var clientData = Context.Klients.AsParallel().Select(x => new { x.Nick, x.Telefon}).ToList();
                //     var clientData = Context.Zamowienies    // your starting point - table in the "from" statement
                //        .Join(Context.Klients, // the source table of the inner join
                //           zam => zam.ID_Klienta,        // Select the primary key (the first part of the "on" clause in an sql "join" statement)
                //           client => client.ID_Klienta,   // Select the foreign key (the second part of the "on" clause)
                //           (zam,client) => new { Zam = zam,Client = client }) // selection
                //        .Where(x => x.Zam.ID_Klienta == x.Client.ID_Klienta);



                //     var filteredClientData = clientData.AsParallel().Select(x => new { x.Client.Nick, x.Client.Telefon }).ToList();

                //     //var restaurantData = Context.Restauracjas.AsParallel().Select(x => new { x.NazwaRestauracji, x.DanieDnia, x.Telefon }).ToList();
                //     var restaurantData = Context.Zamowienies    // your starting point - table in the "from" statement
                //.Join(Context.Restauracjas, // the source table of the inner join
                //   zam => zam.ID_Restauracji,        // Select the primary key (the first part of the "on" clause in an sql "join" statement)
                //   restaurant => restaurant.ID_Restauracji,   // Select the foreign key (the second part of the "on" clause)
                //   (zam, restaurant) => new { Zam = zam, Restaurant = restaurant }) // selection
                //.Where(x => x.Zam.ID_Restauracji == x.Restaurant.ID_Restauracji);
                //     var filteredRestaurantData = restaurantData.AsParallel().Select(x => new { x.Restaurant.NazwaRestauracji,x.Restaurant.DanieDnia ,x.Restaurant.Telefon }).ToList();
            }
        }
        private void btnSync_Click(object sender, EventArgs e)
        {
            using (DomowyFastFoodContext Context = new DomowyFastFoodContext())
            {
                var currentDate = $"{DateTime.Now.ToShortDateString()} \t {DateTime.Now.ToShortTimeString()}";

                lblSyncInfo.Text = currentDate;

                File.WriteAllText(path, $"");
                File.AppendAllText(path, currentDate);

                string urlPoSwiecie = "http://www.poswieciekuchni.pl/menu-dnia/";

                HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument documentPoSwiecie = web.Load(urlPoSwiecie);


                var nodePoSwiecie = documentPoSwiecie.DocumentNode
                                    .SelectNodes("//div[@class='wpb_wrapper']/p[position() > 5]").ToArray();

                string DinnerPoSwiecie = string.Empty;

                if (nodePoSwiecie != null)
                {
                    foreach (var item in nodePoSwiecie)
                    {
                        DinnerPoSwiecie += item.InnerText;
                    }
                }
                var resultPoSwiecie = Context.Restauracjas.SingleOrDefault(x => x.ID_Restauracji == 1);
                if (resultPoSwiecie != null)
                {
                    resultPoSwiecie.DanieDnia = DinnerPoSwiecie;
                    Context.SaveChanges();
                }
                string urlMaximus = "http://maximus.bielsko.pl/";

                HtmlAgilityPack.HtmlDocument documentMaximus = web.Load(urlMaximus);

                //switch (DateTime.Now.DayOfWeek )
                //{
                //    case DayOfWeek.Monday:
                //         var nodeMaximus = documentMaximus.DocumentNode
                //                           .SelectNodes("//div[@class='wpb_wrapper']/p[position() > 5]").ToArray();
                //        break;
                //    default:
                //}
                var nodeMaximus = documentMaximus.DocumentNode
                                  .SelectNodes("//div[@class='views-row views-row-1 views-row-odd views-row-first views-row-last']/div/p[3]").ToArray();
                //*[@id="block-views-dish-of-the-day-block"]/div/div/div/div/div/p[3]
                string DinnerMaximus = string.Empty;

                if (nodeMaximus != null)
                {
                    foreach (var item in nodeMaximus)
                    {
                        DinnerMaximus += item.InnerText;
                    }
                }
                var resultMaximus = Context.Restauracjas.SingleOrDefault(x => x.ID_Restauracji == 2);
                if (resultMaximus != null)
                {
                    resultMaximus.DanieDnia = DinnerMaximus;
                    Context.SaveChanges();
                }
                this.OnLoad(e);
                // frmUserControlPanel form = new frmUserControlPanel(Identity);
                // form.Show();
                //this.Close();


                //            var node = document.DocumentNode.Descendants("P")
                //.Select(y => y.Descendants()
                //.Where(x => x.Attributes["class"].Value == "wpb_wrapper"))
                //.ToArray();

                //HtmlWeb web = new HtmlWeb();
                //var document = web.Load("");

                //HtmlNode[] nodes = document.DocumentNode.SelectNodes("//*[@id=block - views - dish - of - the - day - block]").ToArray();
                //MessageBox.Show(nodes[0].InnerText);
                //var Result = Context.Restauracjas.SingleOrDefault(x => x.NazwaRestauracji == "Maximus");
                //if (Result != null)
                //{
                //    Result.DanieDnia = nodes[0].InnerText;
                //    Context.SaveChanges();
                //}
            }
        }