private void button1_Click(object sender, EventArgs e) { { using (ISession m_Session = m_SessionFactory.OpenSession()) { using (ITransaction tx = m_Session.BeginTransaction()) { try { Gradivo d = new Gradivo(); d.Naslov = textBox1.Text; d.Avtor = textBox2.Text; d.ZvrstGradiva = textBox3.Text; d.LetoIzdaje = Int32.Parse(textBox4.Text); d.NaZalogi = Int32.Parse(textBox5.Text); m_Session.Save(d); tx.Commit(); MessageBox.Show("Vnos gradiva je uspel"); DodajGradivo.ActiveForm.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message);; } } } } }
//edit za gradiva void gbs_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) { switch (e.ListChangedType) { case ListChangedType.ItemChanged: { using (ITransaction tx = m_Session.BeginTransaction()) { Gradivo new_gradivo = (Gradivo)(_gbs.List[e.NewIndex]); if (new_gradivo.Naslov == null) { new_gradivo.Naslov = ""; } if (new_gradivo.Avtor == null) { new_gradivo.Avtor = ""; } if (new_gradivo.ZvrstGradiva == null) { new_gradivo.ZvrstGradiva = ""; } m_Session.Save(new_gradivo); tx.Commit(); } break; } } }