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 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 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 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 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
            {
                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
            {
                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
            {
                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 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 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 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 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 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
            {
                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 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());
            //}
        }
 public void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from c in cont.korisnicis select c;
         korisniciListBox.ItemsSource = query;
     }
 }
 void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from c in cont.narudzbenicas select c;
         narudzbeniceListBox.ItemsSource = query;
     }
 }
 void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from c in cont.nalog_za_skladistenjes select c;
         naloziListBox.ItemsSource = query;
     }
 }
        void updateListBox()
        {
            using (pisModelDataContext cont = new pisModelDataContext())
            {
                var query = from c in cont.prednalog_za_nabavus select c;
                nalogListBox.ItemsSource = query;
            }

        }
 public void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from c in cont.racun_od_dobavljacas select c;
         racunOdDobBox.ItemsSource = query;
         
     }
 }
 void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from c in cont.artiklis select c;
         artikliListBox.ItemsSource = query;
     }
     
 }
 public void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from s in cont.primkas
                     select s;
         primkeBox.ItemsSource = query;
     }
 }
 public void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from s in cont.zahtjevnicas
                     select s;
         zahtjevniceBox.ItemsSource = query;
     }
 }
 void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var jedinice = from jed in cont.jedinica_mjeres
                        select jed;
         jediniceBox.ItemsSource = jedinice;
     }
 }
 public void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from s in cont.organizacijska_jedinicas
                     select s;
         orgJedBox.ItemsSource = query;
     }
 }
 public void updateListBox()
 {
     using (pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from s in cont.potvrda_o_uskladistenom_materijalu_za_sitotisaks
                     select s;
         postvrdaListBox.ItemsSource = query;
     }
 }
 void updateBox()
 {
     string i;
     using(pisModelDataContext cont = new pisModelDataContext())
     {
         var query = from s in cont.jedinica_mjeres
                     select s;
         
         foreach(var st in query){
             i = st.id + "   (" + st.naziv + ")";
             jedMjCombo.Items.Add(i);
             }
     }
 }
        void updateBox()
        {
            string i;
            using (pisModelDataContext cont = new pisModelDataContext())
            {
                var query = from s in cont.artiklis
                            select s;

                foreach (var st in query)
                {
                    i = st.id + "   (" + st.naziv + ")";
                    artikliBox.Items.Add(i);
                }
            }
        }