Esempio n. 1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     using (var entity = new kadryEntities2())
     {
         DateTime data = DateTime.Today;
         try
         {
             var podanie = new Podania
             {
                 idPo            = entity.Podania.Max(u => u.idPo + 1),
                 idO             = Convert.ToInt32(idOferty.Text),
                 dataZlozPo      = data,
                 imiePo          = Imie.Text,
                 nazwiskoPo      = Nazwisko.Text,
                 miasto          = Miasto.Text,
                 adres           = adres.Text,
                 wyksztalceniePo = Wyksztalcenie.Text,
                 dataUrPo        = DataUr.SelectedDate
             };
             entity.Podania.Add(podanie);
         }
         catch (Exception)
         {
             MessageBox.Show("Podano błędne dane");
         }
     }
 }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (box.SelectedIndex != -1)
            {
                //DateTime dateOnly1,dateOnly2;
                using (var entity = new kadryEntities2())
                {
                    int           id;
                    List <String> dane = new List <string>();

                    Pracownicy prac = null;
                    switch (box.SelectedItem.ToString())
                    {
                    case "Dzialy":
                        try {
                            id = entity.Dzialy.Max(u => u.idD);
                        }
                        catch (Exception)
                        {
                            id = 0;
                        }
                        if (id == null)
                        {
                            id = 0;
                        }
                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }
                        var user = new Dzialy {
                            idD = (id + 1)
                        };
                        user.nazwaD  = dane[0];
                        user.miastoD = dane[1];
                        user.adresD  = dane[2];
                        entity.Dzialy.Add(user);

                        break;

                    case "Stanowiska":
                        try
                        {
                            id = entity.Stanowiska.Max(u => u.idS);
                        }
                        catch (Exception)
                        {
                            id = 0;
                        }

                        if (id == null)
                        {
                            id = 0;
                        }

                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }
                        var user2 = new Stanowiska {
                            idS = (id + 1)
                        };
                        user2.nazwa = dane[0];
                        entity.Stanowiska.Add(user2);

                        break;

                    case "Oferty":
                        try
                        {
                            id = entity.Oferty.Max(u => u.idO);
                        }
                        catch (Exception)
                        {
                            id = 0;
                        }
                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }
                        var user3 = new Oferty {
                            idO = (id + 1)
                        };
                        try
                        {
                            System.Console.WriteLine("");
                            System.Console.WriteLine(dane[0] + dane[1]);
                            System.Console.WriteLine("");
                            System.Console.WriteLine(dane[2]);
                            System.Console.WriteLine("");
                            user3.idS        = Convert.ToInt32(dane[0]);
                            user3.idD        = Convert.ToInt32(dane[1]);
                            user3.dataWystaw = Convert.ToDateTime(dane[2]);
                            entity.Oferty.Add(user3);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Wprowadzono błędne dane");
                        }
                        break;

                    case "AppUsers":
                        id = entity.AppUsers.Max(u => u.uId);


                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }
                        var user9 = new AppUsers {
                            uId = (id + 1)
                        };
                        try
                        {
                            user9.login    = dane[0];
                            user9.password = dane[1];
                            user9.Role     = dane[2];
                            entity.AppUsers.Add(user9);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Wprowadzono błędne dane");
                        }
                        break;

                    case "Podania":
                        try
                        {
                            id = entity.Podania.Max(u => u.idPo);
                        }
                        catch (Exception)
                        {
                            id = 0;
                        }


                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }
                        var user4 = new Podania {
                            idPo = (id + 1)
                        };
                        try
                        {
                            user4.idO             = Convert.ToInt32(dane[0]);
                            user4.imiePo          = dane[1];
                            user4.nazwiskoPo      = dane[2];
                            user4.miasto          = dane[3];
                            user4.adres           = dane[4];
                            user4.dataUrPo        = Convert.ToDateTime(dane[5]);
                            user4.wyksztalceniePo = dane[6];
                            user4.dataZlozPo      = Convert.ToDateTime(dane[7]);
                            entity.Podania.Add(user4);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Wprowadzono błędne dane");
                        }
                        break;

                    case "Rozmowy":
                        try
                        {
                            id = entity.Rozmowy.Max(u => u.idR);
                        }catch (Exception)
                        {
                            id = 0;
                        }


                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }
                        Console.WriteLine(dane[0] + dane[1] + dane[2]);
                        var user5 = new Rozmowy {
                            idR = (id + 1)
                        };
                        try {
                            Console.WriteLine(dane[0] + dane[1] + dane[2]);
                            user5.idP         = Convert.ToInt32(dane[0]);
                            user5.idPo        = Convert.ToInt32(dane[1]);
                            user5.dataRozmowy = Convert.ToDateTime(dane[2]);
                            entity.Rozmowy.Add(user5);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Wprowadzono błędne dane");
                        }
                        break;

                    case "stan_dzial":
                        id = entity.stan_dzial.Max(u => u.idD);


                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }
                        try {
                            var user6 = new stan_dzial();
                            user6.idS = Convert.ToInt32(dane[0]);
                            user6.idD = Convert.ToInt32(dane[1]);
                            entity.stan_dzial.Add(user6);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Wprowadzono błędne dane");
                        }


                        break;

                    default:
                        try {
                            id = entity.Pracownicy.Max(u => u.idP);
                        }
                        catch (Exception)
                        {
                            id = 0;
                        }

                        for (int i = 1; i < Stos.Children.Count; i += 2)
                        {
                            dane.Add(Stos.Children[i].ToString().Substring(Stos.Children[i].ToString().IndexOf(":") + 2, Stos.Children[i].ToString().Length - Stos.Children[i].ToString().IndexOf(":") - 2));
                        }

                        var user7 = new Pracownicy {
                            idP = (id + 1)
                        };

                        try
                        {
                            user7.imieP     = dane[0].ToString();
                            user7.nazwiskoP = dane[1].ToString();
                            user7.miastoP   = dane[2].ToString();
                            user7.adresP    = dane[3].ToString();
                            user7.nrTelP    = dane[4];
                            user7.placaP    = Convert.ToDouble(dane[5]);

                            entity.Pracownicy.Add(user7);
                            prac = user7;
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Wprowadzono błędne dane");
                        }
                        break;
                    }
                    try
                    {
                        entity.SaveChanges();
                        if (box.SelectedItem.ToString().Equals("Pracownicy"))
                        {
                            entity.AddPracMore(Convert.ToInt32(dane[6]), Convert.ToInt32(prac.idP), Convert.ToInt32(dane[7]));
                        }

                        MessageBox.Show("Dodawanie powiodło się");
                    }
                    catch (EntitySqlException)
                    {
                        MessageBox.Show("Wystąpił błąd zapisu");
                    }
                }
            }
            else
            {
                MessageBox.Show("Wybierz tebele");
            }
        }