private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int id;
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    skladisnica art = new skladisnica
                    {
                        datum = Convert.ToDateTime(datumPicker.Text),
                        
                    };
                    cont.skladisnicas.InsertOnSubmit(art);
                    cont.SubmitChanges();
                    var entry = (from ee in cont.skladisnicas
                                 select ee).OrderByDescending(ee => ee.id).FirstOrDefault();
                    id = entry.id;
                    iznos.tempSkladisnicaID = id;
                }
                updateListBox();

                //MessageBox.Show(id.ToString());
                stavkeSkladisnicePage stavke = new stavkeSkladisnicePage();
                stavke.idBoxx.Text = id.ToString();
                //MessageBox.Show(iznos.tempID.ToString());
                stavke.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string temp = orgJedBox.SelectedItem.ToString();
                string[] words = temp.Split('(');
                int id;
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    nalog_za_skladistenje art = new nalog_za_skladistenje
                    {
                        datum = Convert.ToDateTime(datumPicker.Text),
                        Nalog_izdao_la = logIn.userName,
                        id_org_jed = Convert.ToInt32(words[0])
                    };
                    cont.nalog_za_skladistenjes.InsertOnSubmit(art);
                    cont.SubmitChanges();
                    var entry = (from ee in cont.nalog_za_skladistenjes
                                 select ee).OrderByDescending(ee => ee.broj_narudzbe).FirstOrDefault();
                    id = entry.broj_narudzbe;
                    iznos.nalogZaSkladistenjeID = id;
                }
                updateListBox();

                //MessageBox.Show(id.ToString());
                stavkeNalogaZaSkladistenje stavke = new stavkeNalogaZaSkladistenje();
                stavke.idBoxx.Text = id.ToString();
                //MessageBox.Show(iznos.tempID.ToString());
                stavke.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
        }
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int id;
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    prednalog_za_nabavu art = new prednalog_za_nabavu
                    {
                        datum = Convert.ToDateTime(datumPicker.Text),
                        vrijeme = vrijemeBox.Text
                    };
                    cont.prednalog_za_nabavus.InsertOnSubmit(art);
                    cont.SubmitChanges();
                    var entry = (from ee in cont.prednalog_za_nabavus
                                 select ee).OrderByDescending(ee => ee.id).FirstOrDefault();
                    id = entry.id;
                    iznos.prednalogZaNabavuID = id;
                }
                updateListBox();

                //MessageBox.Show(id.ToString());
                stavkePrednalogaZaNabavuPage stavke = new stavkePrednalogaZaNabavuPage();
                stavke.idBoxx.Text = id.ToString();
                //MessageBox.Show(iznos.tempID.ToString());
                stavke.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //try
            //{
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    racun_od_dobavljaca racun = new racun_od_dobavljaca
                    {
                        datum = Convert.ToDateTime(datumBox.Text),
                        adresa = adresaBox.Text
                    };
                    cont.racun_od_dobavljacas.InsertOnSubmit(racun);
                    cont.SubmitChanges();
                    var entry = (from ee in cont.racun_od_dobavljacas
                                 select ee).OrderByDescending(ee => ee.br_racuna).FirstOrDefault();
                    id = entry.br_racuna;
                    iznos.tempID = entry.br_racuna;
                }
                updateListBox();

                //MessageBox.Show(id.ToString());
                stavkeRacunaOdDobPage stavke = new stavkeRacunaOdDobPage();
                stavke.idBoxx.Text = id.ToString();
                //MessageBox.Show(iznos.tempID.ToString());
                stavke.ShowDialog();

            //}

            //catch (Exception ex)
            //{
               // MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            //}
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string temp = izdatnicaBox.SelectedItem.ToString();
                string[] words = temp.Split('(');
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    var query = from c in cont.zahtjevnicas
                                where c.id == Convert.ToInt32(idBox.Text)
                                select c;
                    foreach (var ord in query)
                    {
                        ord.id = Convert.ToInt32(idBox.Text);
                        ord.datum = Convert.ToDateTime(datumPicker.Text);
                        ord.id_izdatnice = Convert.ToInt32(words[0]);
                        ord.odgOsoba = logIn.userName;
                        
                    }
                    cont.SubmitChanges();
                }

                stavkeZahtjevnicePage stavke = new stavkeZahtjevnicePage();
                stavke.idBoxx.Text = idBox.Text.ToString();
                iznos.tempPrimkaID = Convert.ToInt32(idBox.Text);
                stavke.ShowDialog();
                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!" + ex.Message.ToString());
            }
        }
 private void saveButton_Click(object sender, RoutedEventArgs e)
 {
     string r;
     if (roleBox.Text == "Administrator") r = "admin";
     else r = "user";
     try
     {
         using (pisModelDataContext cont = new pisModelDataContext())
         {
             korisnici art = new korisnici
             {
                 korisnicko_ime = userName.Text,
                 lozinka = Password.Text,
                 ovlast = r
             };
             cont.korisnicis.InsertOnSubmit(art);
             cont.SubmitChanges();
         }
         updateListBox();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
     }
 }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int id;
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    potvrda_o_uskladistenom_materijalu_za_sitotisak art = new potvrda_o_uskladistenom_materijalu_za_sitotisak
                    {
                        datum = Convert.ToDateTime(datumPicker.Text),
                        odgOsoba = logIn.userName
                    };
                    cont.potvrda_o_uskladistenom_materijalu_za_sitotisaks.InsertOnSubmit(art);
                    cont.SubmitChanges();
                    var entry = (from ee in cont.potvrda_o_uskladistenom_materijalu_za_sitotisaks
                                 select ee).OrderByDescending(ee => ee.id).FirstOrDefault();
                    id = entry.id;
                    iznos.tempPotvrdaOUskladistenomMaterijaluZaSitotisakID = id;
                }
                updateListBox();

                //MessageBox.Show(id.ToString());
                stavkePotvrdeZaSitotisak stavke = new stavkePotvrdeZaSitotisak();
                stavke.idBoxx.Text = id.ToString();

                //MessageBox.Show(iznos.tempID.ToString());
                stavke.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
        }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (pisModelDataContext con = new pisModelDataContext())
                {

                    var jedinica = jediniceBox.SelectedItems;
                    //MessageBox.Show(jedinica.ToString());
                    foreach (jedinica_mjere j in jedinica)
                    {
                        var _jmj = (from jed in con.jedinica_mjeres
                                    where jed.id == j.id
                                    select jed).First();
                        con.jedinica_mjeres.DeleteOnSubmit(_jmj);
                        con.SubmitChanges();
                    }
                    updateListBox();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
            
    }
 private void saveButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (pisModelDataContext cont = new pisModelDataContext())
         {
             var query = from c in cont.izdatnicas
                         where c.id == Convert.ToInt32(idBox.Text)
                         select c;
             foreach (var ord in query)
             {
                 ord.datum = Convert.ToDateTime(datumPicker.Text);
                 ord.vrijeme = vrijemeBox.Text;
             }
             cont.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Dogodila se pogreška!!!" + ex.Message.ToString());
     }
     stavkeIzdatnicePage stavke = new stavkeIzdatnicePage();
     stavke.idBoxx.Text = idBox.Text.ToString();
     iznos.tempIzdatnicaID = Convert.ToInt32(idBox.Text);
     stavke.ShowDialog();
     this.Close();
 }
 private void saveButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (pisModelDataContext cont = new pisModelDataContext())
         {
             var query = from c in cont.racun_od_dobavljacas
                         where c.br_racuna == Convert.ToInt32(idBox.Text)
                         select c;
             foreach (var ord in query)
             {
                 ord.datum = Convert.ToDateTime(datumBox.Text);
                 ord.adresa = adresaBox.Text;
             }
             cont.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Dogodila se pogreška!!!" + ex.Message.ToString());
     }
     stavkeRacunaOdDobPage stavke = new stavkeRacunaOdDobPage();
     stavke.idBoxx.Text = idBox.Text.ToString();
     iznos.tempID = Convert.ToInt32(idBox.Text);
     stavke.ShowDialog();
     this.Close();
 }
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string temp = orgJedBox.SelectedItem.ToString();
                string[] words = temp.Split('(');
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    var query = from c in cont.narudzbenicas
                                where c.id == Convert.ToInt32(idBox.Text)
                                select c;
                    foreach (var ord in query)
                    {
                        ord.id = Convert.ToInt32(idBox.Text);
                        ord.id_org_jed = Convert.ToInt32(words[0]);
                        ord.datum = Convert.ToDateTime(datumPicker.Text);
                        ord.vrijeme = vrijemeBox.Text;
                    }
                    cont.SubmitChanges();
                }

                stavkeNarudzbenice stavke = new stavkeNarudzbenice();
                stavke.idBoxx.Text = idBox.Text.ToString();
                iznos.tempNarudzbenicaID = Convert.ToInt32(idBox.Text);
                stavke.ShowDialog();
                this.Close();
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
            
        }
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string temp = sifraCombo.SelectedItem.ToString();
                string[] words = temp.Split('(');
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    var query = from c in cont.stavke_naloga_za_skladistenjes
                                where c.id == Convert.ToInt32(idBox.Text)
                                select c;
                    foreach (var ord in query)
                    {
                        ord.kolicina = Convert.ToInt32(kolicinaBox.Text);
                        ord.id_artikla = Convert.ToInt32(words[0]);
                    }
                    cont.SubmitChanges();
                    
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!" + ex.Message.ToString());
            }

            
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string temp = izdatnicaBox.SelectedItem.ToString();
                string[] words = temp.Split('(');
                int id;
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    zahtjevnica art = new zahtjevnica
                    {
                        datum = Convert.ToDateTime(datumPicker.Text),
                        id_izdatnice = Convert.ToInt32(words[0])
                    };
                    cont.zahtjevnicas.InsertOnSubmit(art);
                    cont.SubmitChanges();
                    var entry = (from ee in cont.zahtjevnicas
                                 select ee).OrderByDescending(ee => ee.id).FirstOrDefault();
                    id = entry.id;
                    iznos.tempZahtjevnicaID = id;
                }
                updateListBox();

                //MessageBox.Show(id.ToString());
                stavkeZahtjevnicePage stavke = new stavkeZahtjevnicePage();
                stavke.idBoxx.Text = id.ToString();
                //MessageBox.Show(iznos.tempID.ToString());
                stavke.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
        }
 private void saveButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string temp = idJedCijBox.SelectedItem.ToString();
         string[] words = temp.Split('(');
         using (pisModelDataContext cont = new pisModelDataContext())
         {
             var query = from c in cont.artiklis
                         where c.id == Convert.ToInt32(idBox.Text)
                         select c;
             foreach (var ord in query)
             {
                 ord.id = Convert.ToInt32(idBox.Text);
                 ord.naziv = nazivBox.Text;
                 ord.vrsta = vrstaBox.Text;
                 ord.id_jedinice_mjere = Convert.ToInt32(words[0]);
                 ord.jedinicna_cijena = Convert.ToInt32(jedCijenaBox.Text);
             }
             cont.SubmitChanges();
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
     }
 }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string temp = orgJedBox.SelectedItem.ToString();
                string[] words = temp.Split('(');
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    var query = from c in cont.nalog_za_skladistenjes
                                where c.broj_narudzbe == Convert.ToInt32(idBox.Text)
                                select c;
                    foreach (var ord in query)
                    {
                        ord.broj_narudzbe = Convert.ToInt32(idBox.Text);
                        ord.id_org_jed = Convert.ToInt32(words[0]);
                        ord.datum = Convert.ToDateTime(datumPicker.Text);
                        ord.Nalog_izdao_la = logIn.userName;
                        
                    }
                    cont.SubmitChanges();
                }

                stavkeNalogaZaSkladistenje stavke = new stavkeNalogaZaSkladistenje();
                stavke.idBoxx.Text = idBox.Text.ToString();
                iznos.nalogZaSkladistenjeID = Convert.ToInt32(idBox.Text);
                stavke.ShowDialog();
                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
            
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (pisModelDataContext cont = new pisModelDataContext())
                {
                    var query = from c in cont.potvrda_o_uskladistenom_materijalu_za_sitotisaks
                                where c.id == Convert.ToInt32(idBox.Text)
                                select c;
                    foreach (var ord in query)
                    {
                        ord.datum = Convert.ToDateTime(datumPicker.Text);
                        ord.odgOsoba = logIn.userName;
                    }
                    cont.SubmitChanges();
                }

                stavkePotvrdeZaSitotisak stavke = new stavkePotvrdeZaSitotisak();
                stavke.idBoxx.Text = idBox.Text.ToString();
                iznos.tempPotvrdaOUskladistenomMaterijaluZaSitotisakID = Convert.ToInt32(idBox.Text);
                stavke.ShowDialog();
                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!" + ex.Message.ToString());
            }
        }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (pisModelDataContext con = new pisModelDataContext())
                {

                    var item = primkeBox.SelectedItems;
                    //MessageBox.Show(jedinica.ToString());

                    foreach (primka j in item)
                    {
                        var _item = from _iteem in con.stavke_primkes
                                    where _iteem.id_primke == j.id
                                    select _iteem;
                        con.stavke_primkes.DeleteAllOnSubmit(_item);
                        con.SubmitChanges();
                    }

                    foreach (primka j in item)
                    {
                        var itm = (from it in con.primkas
                                   where it.id == j.id
                                   select it).First();

                        con.primkas.DeleteOnSubmit(itm);
                        //con.stavke_racuna_od_dobavljacas.DeleteOnSubmit(_itm);
                        con.SubmitChanges();
                    }
                    updateListBox();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!" + ex.Message.ToString());
            }
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            using (pisModelDataContext cont = new pisModelDataContext())
            {
                jedinica_mjere jedMj = new jedinica_mjere
                {
                    naziv = nameJedMjere.Text.ToString()
                };
                cont.jedinica_mjeres.InsertOnSubmit(jedMj);
                cont.SubmitChanges();
                MessageBox.Show("Spremljeno");
                updateListBox();
            }

        }
 private void saveButton_Click(object sender, RoutedEventArgs e)
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from c in cont.jedinica_mjeres
                     where c.id == Convert.ToInt32(IDjmj.Text)
                     select c;
         foreach (var ord in query)
         {
             ord.id = Convert.ToInt32(IDjmj.Text);
             ord.naziv = newName.Text;
             // Insert any additional changes to column values.
         }
         cont.SubmitChanges();
     }
     this.Close();
 }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            using (pisModelDataContext con = new pisModelDataContext())
            {

                var item = korisniciListBox.SelectedItems;
                //MessageBox.Show(jedinica.ToString());
                foreach (korisnici j in item)
                {
                    var _itm = (from it in con.korisnicis
                                where it.id == j.id
                                select it).First();
                    con.korisnicis.DeleteOnSubmit(_itm);
                    con.SubmitChanges();
                }
                updateListBox();
            }
        }
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            string temp = jedMjCombo.SelectedItem.ToString();
            string[] words = temp.Split('(');
            using (pisModelDataContext cont = new pisModelDataContext())
            {
                artikli art = new artikli
                {
                    naziv = nazivBox.Text,
                    jedinicna_cijena = Convert.ToInt32(jedCijena.Text),
                    vrsta = vrstaBox.Text,
                    id_jedinice_mjere = Convert.ToInt32(words[0])
                };
                cont.artiklis.InsertOnSubmit(art);
                cont.SubmitChanges();
            }
            updateListBox();

        }
 private void addButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (pisModelDataContext cont = new pisModelDataContext())
         {
             organizacijska_jedinica art = new organizacijska_jedinica
             {
                 naziv = nazivBox.Text
             };
             cont.organizacijska_jedinicas.InsertOnSubmit(art);
             cont.SubmitChanges();
         }
         updateListBox();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
     }
 }
 private void saveButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (pisModelDataContext cont = new pisModelDataContext())
         {
             var query = from c in cont.organizacijska_jedinicas
                         where c.id == Convert.ToInt32(idBox.Text)
                         select c;
             foreach (var ord in query)
             {
                 ord.id = Convert.ToInt32(idBox.Text);
                 ord.naziv = nazivBox.Text;
             }
             cont.SubmitChanges();
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
     }
 }
 private void addButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string temp = artikliBox.SelectedItem.ToString();
         string[] words = temp.Split('(');
         using (pisModelDataContext cont = new pisModelDataContext())
         {
             stavke_zahtjevnice racun = new stavke_zahtjevnice
             {
                 id_zahtjevnice = Convert.ToInt32(idBoxx.Text.ToString()),
                 kolicina = Convert.ToInt32(kolicinaBox.Text),
                 id_artikla = Convert.ToInt32(words[0])
             };
             cont.stavke_zahtjevnices.InsertOnSubmit(racun);
             cont.SubmitChanges();
         }
         updateListBox();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Dogodila se pogreška!!!" + ex.Message.ToString());
     }
 }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (pisModelDataContext con = new pisModelDataContext())
                {

                    var item = artikliListBox.SelectedItems;
                    //MessageBox.Show(jedinica.ToString());
                    foreach (artikli j in item)
                    {
                        var _itm = (from it in con.artiklis
                                    where it.id == j.id
                                    select it).First();
                        con.artiklis.DeleteOnSubmit(_itm);
                        con.SubmitChanges();
                    }
                    updateListBox();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
            
        }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (pisModelDataContext con = new pisModelDataContext())
                {

                    var item = stavkeZahtjeniceBox.SelectedItems;
                    //MessageBox.Show(jedinica.ToString());
                    foreach (stavkee j in item)
                    {
                        //stavke_racuna_od_dobavljaca sta = (stavke_racuna_od_dobavljaca)j;
                        var itm = (from it in con.stavke_zahtjevnices
                                   where it.id == j.id
                                   select it).First();
                        con.stavke_zahtjevnices.DeleteOnSubmit(itm);
                        con.SubmitChanges();
                    }
                    updateListBox();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dogodila se pogreška!!!\n" + ex.Message.ToString());
            }
        }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            using (pisModelDataContext con = new pisModelDataContext())
            {

                var item = racunOdDobBox.SelectedItems;
                //MessageBox.Show(jedinica.ToString());
                foreach (stavkee j in item)
                {
                    //stavke_racuna_od_dobavljaca sta = (stavke_racuna_od_dobavljaca)j;
                    var itm = (from it in con.stavke_racuna_od_dobavljacas
                               where it.jel == j.jel
                               select it).First();
                    con.stavke_racuna_od_dobavljacas.DeleteOnSubmit(itm);
                    con.SubmitChanges();
                }
                updateListBox();
            }
            
        }