-1

I have a problem with class which should: issue couple invoices, shows/update progress bar and save to nhibernate classes some values. Below code shows function which calls WyemitujFakture and display progress bar windows.

             private void BtOK_Click(object sender, EventArgs e)
              {
                lista.Add(2);
                lista.Add(8);
                liczbaWygenerowach = 0;
                ilosc_zrobionych = 0;
                fpb = new FrmProgressBar("Emisja faktur potwierdzonych, proszę czekać...");
                fpb.Show();
                Application.DoEvents();
                WyemitujFakture(lista);
                fpb.Close();
              }

Windows form shows progress bar and invoices are generate but can not save values from nHibernate classes. It looks like lines: fs.Save(); and Session.Flush(); do not work. Have You got any idea how to resolve this problem?

private void WyemitujFakture(List<int> lista)
 {
 foreach (int knh_id in lista)
  {
try
{
    if (luk.Count > 0)
    {
        FakturySprzedazy fs = new FakturySprzedazy();
        fs.FKS_AKCYZA = false;
        fs.FKS_CZY_KLON = false;
        fs.FKS_DATA_DOW_KS = Convert.ToDateTime(MTBDataZapisuDoFK.Text);
        fs.FKS_DATA_FAKTURY = Convert.ToDateTime(MTBDataFaktury.Text);
        fs.FKS_DATA_SPRZEDAZY = Convert.ToDateTime(MTBDataSprzedazy.Text);
        fs.Save();
        Session.Flush();
        liczbaWygenerowach++;
    }

}
catch (Exception ex)
{
    MessageBox.Show("Nie mozna wyemitowac faktury dla kontrahenta o id = " + knh_id.ToString() + " " + ex.Message);
}
ilosc_zrobionych++;

fpb.PBStan.Value = (int)((100 * ilosc_zrobionych) / liczbaKontrahentow);
Application.DoEvents();
 }
 }

Many thanks for help in advance

JacekRobak85
  • 93
  • 1
  • 10
  • Exact text of error messages / exceptions? PostgreSQL version? Have you examined the PostgreSQL error logs to see what, if anything, appears there? – Craig Ringer Sep 17 '12 at 11:42

1 Answers1

1

Dear Craig Ringer,

Thank U for Your quick reaction. I have not got any error message and I have version 9,1 of postgresql.

I have found solution:)

Function "WyemitujFakture" is in thread so it hasnot got access to SessionScope object which is created in main thread. I added to function WyemitujFakture 4 lines:

SessionScope session2 = new SessionScope(FlushAction.Never);
                    fs.Save();
                    session2.Flush();
if (session2 != null) session2.Dispose();

Above 4 lines have resolved problem. Below I attached whole function which works properly:

private void WyemitujFakture(List<int> lista)
{
foreach (int knh_id in lista)
{
 try
{
if (luk.Count > 0)
{
    FakturySprzedazy fs = new FakturySprzedazy();
    fs.FKS_AKCYZA = false;
    fs.FKS_CZY_KLON = false;
    fs.FKS_DATA_DOW_KS = Convert.ToDateTime(MTBDataZapisuDoFK.Text);
    fs.FKS_DATA_FAKTURY = Convert.ToDateTime(MTBDataFaktury.Text);
    fs.FKS_DATA_SPRZEDAZY = Convert.ToDateTime(MTBDataSprzedazy.Text);
    SessionScope session2 = new SessionScope(FlushAction.Never);
                    fs.Save();
                    session2.Flush();
   session2.Flush();


   if (session2 != null) session2.Dispose();
   Session.Flush();
    liczbaWygenerowach++;
}

}
catch (Exception ex)
{
MessageBox.Show("Nie mozna wyemitowac faktury dla kontrahenta o id = " + knh_id.ToString() + " " + ex.Message);
}
ilosc_zrobionych++;

fpb.PBStan.Value = (int)((100 * ilosc_zrobionych) / liczbaKontrahentow);
Application.DoEvents();
}
}

Thank You for Your engagement!!!!

Best regards!!!!

JacekRobak85
  • 93
  • 1
  • 10