Index: /trunk/BazaReklam/AddClient.cs
===================================================================
--- /trunk/BazaReklam/AddClient.cs (revision 597)
+++ /trunk/BazaReklam/AddClient.cs (revision 611)
@@ -246,4 +246,9 @@
             errorProvider.SetError(txtClientCode, sb.ToString());
         }
+
+        private void AddClient_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            rEKLAMADataSet.KLIENCI.RejectChanges();
+        }
     }
 }
Index: /trunk/BazaReklam/ZamowieniaForm.cs
===================================================================
--- /trunk/BazaReklam/ZamowieniaForm.cs (revision 603)
+++ /trunk/BazaReklam/ZamowieniaForm.cs (revision 611)
@@ -6,4 +6,5 @@
 using System.Windows.Forms;
 using Baza_Reklam.Classes.Helpers;
+using Baza_Reklam.Classes.Interfaces;
 
 namespace Baza_Reklam
@@ -294,35 +295,37 @@
             if (zamowieniaBindingSource.Current == null) return;
 
-            if (rEKLAMADataSet.REKLAMA.Rows.Count <= 0)
-            {
-                MessageBox.Show("Proszê dodaæ przynajmniej jedn¹ reklamê do zamówienia.", "Faktura");
-                return;
-            }
-            
-            Cursor = Cursors.WaitCursor;
-
-            DataRowView z = (DataRowView) zamowieniaBindingSource.Current;
-            REKLAMADataSet.zamowieniaRow zamowienie = (REKLAMADataSet.zamowieniaRow) z.Row;
-
-            REKLAMADataSet.KLIENCIRow _klient =
-                (REKLAMADataSet.KLIENCIRow) klienciTableAdapter.GetDataByCustomerId(zamowienie.idKlienta).Rows[0];
-            string errorMessage = czyMoznaZafakturowac(zamowienie, _klient);
-
-            if (errorMessage != string.Empty)
-            {
-                MessageBox.Show(errorMessage);
+            try
+            {
+                Cursor = Cursors.WaitCursor;
+
+                DataRowView z = (DataRowView) zamowieniaBindingSource.Current;
+                REKLAMADataSet.zamowieniaRow zamowienie = (REKLAMADataSet.zamowieniaRow) z.Row;
+
+                REKLAMADataSet.KLIENCIRow klientRow =
+                    (REKLAMADataSet.KLIENCIRow) klienciTableAdapter.GetDataByCustomerId(zamowienie.idKlienta).Rows[0];
+
+                InitIssueTables(zamowienie);
+
+                string errorMessage = CzyMoznaZafakturowac(zamowienie, klientRow);
+
+                if (errorMessage != string.Empty)
+                {
+                    MessageBox.Show(errorMessage, "Fakturowanie");
+                    Cursor = Cursors.Default;
+                    return;
+                }
+
+                WystawFakture(zamowienie, klientRow, false);
+
+                RestoreConnections();
+
+                zamowieniaBindingSource.ResetBindings(false);
+
+                fAKTURYBindingSource.MoveLast();
+            }
+            finally
+            {
                 Cursor = Cursors.Default;
-                return;
-            }
-
-            WystawFakture(zamowienie, _klient, false);
-
-            RestoreConnections();
-
-            zamowieniaBindingSource.ResetBindings(false);
-
-            fAKTURYBindingSource.MoveLast();
-
-            Cursor = Cursors.Default;
+            }
         }
 
@@ -523,17 +526,14 @@
         }
 
-        private void PobierzOznaczEmisje(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.FAKTURYRow naglowekFaktury)
+
+        private void InitIssueTables(REKLAMADataSet.zamowieniaRow zamowienie)
         {
             emisjeTableAdapter.ClearBeforeFill = false;
             datyWydanTableAdapter.ClearBeforeFill = false;
+            rEKLAMADataSet.UKAZE_SIE_W_NR.Clear();
+            rEKLAMADataSet.DatyWydan.Clear();
 
             REKLAMADataSet.DatyWydanDataTable t = datyWydanTableAdapter.GetDataByPierwszaEmisjaWZamowieniu(zamowienie.idZamowienia);
-
-            if (t.Rows.Count == 0)
-            {
-                //TODO: moze lepiej uzyc MessageBox'a i return niz wywalac wyjatek...?
-                // wyjatki sa dosc kosztowne dla aplikacji
-                throw new Exception("Nie ma co fakturowaæ!");
-            }
+            if (t.Rows.Count <= 0) return;
 
             DateTime d = t[0].DATA_W;
@@ -575,9 +575,10 @@
                 reklama.EndEdit();
             }
-
-            if (rEKLAMADataSet.UKAZE_SIE_W_NR.Rows.Count <= 0)
-                throw new ApplicationException("Nie znaleziono ¿adnych emisji do zafakturowania! (" +
-                                               zamowienie.idZamowienia + ": " + StringHelper.ListToString(adIds, ",") + ")");
-
+        }
+
+
+        private void PobierzOznaczEmisje(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.FAKTURYRow naglowekFaktury)
+        {
+            //InitIssueTables(zamowienie);
 
             if (zamowienie.IsdataOstatniejZafakturowanejEmisjiNull())
@@ -635,5 +636,5 @@
         {
             SLOWNIKDataSet.AGENCIRow agent = (SLOWNIKDataSet.AGENCIRow)agenciTableAdapter.GetDataByKodAgenta(zamowienie.kodAgenta).Rows[0];
-            InvoiceProvider invoiceProvider = InvoiceProviderFactory.GetInvoiceProviderById(agent.InvoiceProviderId);
+            IInvoiceProvider invoiceProvider = InvoiceProviderFactory.GetInvoiceProviderById(agent.InvoiceProviderId);
 
 
@@ -709,5 +710,5 @@
                 if (kurs.Count == 0)
                 {
-                    throw new Exception("B³¹d przy pobieraniu kursu waluty.");
+                    throw new ApplicationException("B³¹d przy pobieraniu kursu waluty.");
                 }
 
@@ -730,5 +731,5 @@
         
 
-        private string czyMoznaZafakturowac(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.KLIENCIRow klientRow)
+        private string CzyMoznaZafakturowac(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.KLIENCIRow klientRow)
         {
             string errorMessage = string.Empty;
@@ -738,17 +739,35 @@
             errorMessage += zamowienie.IsidKontaNull() ? "Nie wybrano konta. \n" : "";
             errorMessage += zamowienie.IssposobZaplatyNull() ? "Nie wybrano sposobu zap³aty. \n" : "";
-            errorMessage += klientRow.IsCountryNull() || klientRow.Country == string.Empty ? "Brak pañstwa klienta. \n" : "";
-            errorMessage += klientRow.IsAdres_FkaturaNull() || klientRow.Adres_Fkatura == string.Empty ? "Brak adresu faktury klienta. \n" : "";
-            errorMessage += klientRow.IsNipNull() || klientRow.Nip == string.Empty ? "Brak nipu klienta. \n" : "";
+            errorMessage += string.IsNullOrEmpty(klientRow.Country) ? "Brak pañstwa klienta. \n" : "";
+            errorMessage += string.IsNullOrEmpty(klientRow.Adres_Fkatura) ? "Brak adresu faktury klienta. \n" : "";
+            errorMessage +=  string.IsNullOrEmpty(klientRow.Nip) ? "Brak nipu klienta. \n" : "";
 
             if (klientRow.Country != "Polska")
-            {
-                errorMessage += klientRow.IsnipKrajNull() || klientRow.nipKraj == string.Empty ? "Brak symbolu kraju w nipie klienta. \n" : "";
+                errorMessage += string.IsNullOrEmpty(klientRow.nipKraj) ? "Brak symbolu kraju w nipie klienta. \n" : "";
+
+            if (rEKLAMADataSet.REKLAMA.Rows.Count <= 0)
+            {
+                // try to load the ads once again in case something went wrong before...
+                rEKLAMATableAdapter.FillByIdZamowienia(rEKLAMADataSet.REKLAMA, zamowienie.idZamowienia);
+
+                if (rEKLAMADataSet.REKLAMA.Rows.Count <= 0)
+                    errorMessage += "Proszê dodaæ przynajmniej jedn¹ reklamê do zamówienia \n";
             }
 
             if (rEKLAMADataSet.REKLAMA.Select("[ZATWIERDZONO DO DRUKU] = 0").Length > 0)
-            {
                 errorMessage += "W zamówieniu s¹ reklamy niezatwierdzone do druku \n";
-            }
+
+            if (errorMessage.Length > 0)
+                return errorMessage;
+
+            if (rEKLAMADataSet.UKAZE_SIE_W_NR.Rows.Count <= 0)
+            {
+                errorMessage += "Nie znaleziono ¿adnych emisji do zafakturowania \n";
+                return errorMessage;
+            }
+
+            REKLAMADataSet.DatyWydanDataTable t = datyWydanTableAdapter.GetDataByPierwszaEmisjaWZamowieniu(zamowienie.idZamowienia);
+            if (t.Rows.Count == 0)
+                errorMessage += "Nie znaleziono ¿adnych emisji do zafakturowania \n";
 
             return errorMessage;
@@ -1359,10 +1378,4 @@
             if (zamowieniaBindingSource.Current == null) return;
 
-            if (rEKLAMADataSet.REKLAMA.Rows.Count <= 0)
-            {
-                MessageBox.Show("Proszê dodaæ przynajmniej jedn¹ reklamê do zamówienia.", "Faktura proforma");
-                return;
-            }
-
             Cursor = Cursors.WaitCursor;
 
@@ -1372,9 +1385,12 @@
             REKLAMADataSet.KLIENCIRow _klient =
                 (REKLAMADataSet.KLIENCIRow) klienciTableAdapter.GetDataByCustomerId(zamowienie.idKlienta).Rows[0];
-            string errorMessage = czyMoznaZafakturowac(zamowienie, _klient);
+
+            InitIssueTables(zamowienie);
+
+            string errorMessage = CzyMoznaZafakturowac(zamowienie, _klient);
 
             if (errorMessage != string.Empty)
             {
-                MessageBox.Show(errorMessage);
+                MessageBox.Show(errorMessage, "Fakturowanie - Proforma");
                 Cursor = Cursors.Default;
                 return;
@@ -1391,5 +1407,7 @@
             {
                 DataRow[] rows = rEKLAMADataSet.FAKTURY.Select("id_faktury=" + id);
-                usunFakture((REKLAMADataSet.FAKTURYRow) rows[0]);
+                if (rows.Length > 0)
+                    usunFakture((REKLAMADataSet.FAKTURYRow) rows[0]);
+                
                 RestoreConnections();
                 Cursor = Cursors.Default;
Index: /trunk/BazaReklam/Docs/versioninfo.html
===================================================================
--- /trunk/BazaReklam/Docs/versioninfo.html (revision 604)
+++ /trunk/BazaReklam/Docs/versioninfo.html (revision 611)
@@ -6,4 +6,13 @@
 <body>
    <h1>Baza reklam - Informacje o wersji</h1>
+   <div>
+        <a id="1.1.6" />
+        <h2>Wersja 1.1.6 (2009-04-27)</h2>
+        <p>Opis zmian wprowadzonych do wersji 1.1.6</p>
+        <ul>
+            <li>Zgłoszenie #160: Bieżące poprawki na podstawie logu błędów</li>
+            <li>Zgłoszenie #165: Naprawa błędów występujących podczas aktualizacji</li>
+        </ul>
+   </div>
    <div>
         <a id="1.1.5" />
Index: /trunk/BazaReklam/Baza Reklam.csproj
===================================================================
--- /trunk/BazaReklam/Baza Reklam.csproj (revision 602)
+++ /trunk/BazaReklam/Baza Reklam.csproj (revision 611)
@@ -114,4 +114,5 @@
     <Compile Include="Classes\Helpers\StringHelper.cs" />
     <Compile Include="Classes\Helpers\WebRequestHelper.cs" />
+    <Compile Include="Classes\Interfaces\IInvoiceProvider.cs" />
     <Compile Include="Classes\Interfaces\IForm.cs" />
     <Compile Include="Classes\Model\Invoice.cs" />
Index: /trunk/BazaReklam/AddClient.Designer.cs
===================================================================
--- /trunk/BazaReklam/AddClient.Designer.cs (revision 597)
+++ /trunk/BazaReklam/AddClient.Designer.cs (revision 611)
@@ -1050,4 +1050,5 @@
             this.Text = "Dodaj/modyfikuj klienta";
             this.Load += new System.EventHandler(this.AddClient_Load);
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AddClient_FormClosing);
             this.gbAddress.ResumeLayout(false);
             this.gbAddress.PerformLayout();
Index: /trunk/BazaReklam/FakturowaniePoznanKatowice.cs
===================================================================
--- /trunk/BazaReklam/FakturowaniePoznanKatowice.cs (revision 602)
+++ /trunk/BazaReklam/FakturowaniePoznanKatowice.cs (revision 611)
@@ -594,5 +594,6 @@
             if (pozycjeFakturDlaKlientow.Rows.Count == 0 || naglowkiFakturDlaKlientow.Rows.Count == 0)
             {
-                throw new Exception("Nie ma co fakturowaæ");
+                //TODO: check is there is anythig to invoice before callind that method
+                throw new ApplicationException("Nie ma co fakturowaæ - Poznañ | Katowice");
             }
 
Index: /trunk/BazaReklam/Classes/Interfaces/IInvoiceProvider.cs
===================================================================
--- /trunk/BazaReklam/Classes/Interfaces/IInvoiceProvider.cs (revision 611)
+++ /trunk/BazaReklam/Classes/Interfaces/IInvoiceProvider.cs (revision 611)
@@ -0,0 +1,18 @@
+namespace Baza_Reklam.Classes.Interfaces
+{
+    public interface IInvoiceProvider
+    {
+        int Id { get; set; }
+        string ShortName { get; set; }
+        string Name { get; set; }
+        string Street { get; set; }
+        string City { get; set; }
+        string PostCode { get; set; }
+        string Country { get; set; }
+        string Phone { get; set; }
+        string TaxNumber { get; set; }
+        string TaxCountryPrefix { get; set; }
+        int SystemKsiegowyId { get; set; }
+        string GetAddress();
+    }
+}
Index: /trunk/BazaReklam/Classes/Helpers/PdfHelper.cs
===================================================================
--- /trunk/BazaReklam/Classes/Helpers/PdfHelper.cs (revision 607)
+++ /trunk/BazaReklam/Classes/Helpers/PdfHelper.cs (revision 611)
@@ -24,7 +24,4 @@
         public bool DisplayPdf()
         {
-            throw new System.Net.WebException("test");
-
-
             string url = ConfigurationHelper.GetSettingByKey("Application.Pdf.Date") ??
              "http://truck.pl/ogloszenia/_getFile.asp?pdfdate,{0},,";
Index: /trunk/BazaReklam/Classes/InvoiceProviderFactory.cs
===================================================================
--- /trunk/BazaReklam/Classes/InvoiceProviderFactory.cs (revision 539)
+++ /trunk/BazaReklam/Classes/InvoiceProviderFactory.cs (revision 611)
@@ -3,4 +3,5 @@
 using System.Data;
 using System.Data.SqlClient;
+using Baza_Reklam.Classes.Interfaces;
 
 namespace Baza_Reklam
@@ -9,5 +10,5 @@
     {
         private static InvoiceProviderFactory _instance;
-        private readonly List<InvoiceProvider> _invoiceProviders = new List<InvoiceProvider>();
+        private readonly List<IInvoiceProvider> _invoiceProviders = new List<IInvoiceProvider>();
 
         private InvoiceProviderFactory()
@@ -80,21 +81,21 @@
         }
 
-        public static List<InvoiceProvider> GetInvoiceProviders()
+        public static List<IInvoiceProvider> GetInvoiceProviders()
         {
             return Instance._invoiceProviders;
         }
 
-        public static InvoiceProvider GetInvoiceProviderById(int invoiceProviderId)
+        public static IInvoiceProvider GetInvoiceProviderById(int invoiceProviderId)
         {
             return
                 Instance._invoiceProviders.Find(
-                    delegate(InvoiceProvider invoiceProvider) { return invoiceProvider.Id == invoiceProviderId; });
+                    delegate(IInvoiceProvider invoiceProvider) { return invoiceProvider.Id == invoiceProviderId; });
         }
 
-        public static List<InvoiceProvider> GetInvoiceProvidersById(int invoiceProviderId)
+        public static List<IInvoiceProvider> GetInvoiceProvidersById(int invoiceProviderId)
         {
             return
                 Instance._invoiceProviders.FindAll(
-                    delegate(InvoiceProvider invoiceProvider) { return invoiceProvider.Id == invoiceProviderId; });
+                    delegate(IInvoiceProvider invoiceProvider) { return invoiceProvider.Id == invoiceProviderId; });
         }
     }
Index: /trunk/BazaReklam/Classes/InvoiceProvider.cs
===================================================================
--- /trunk/BazaReklam/Classes/InvoiceProvider.cs (revision 539)
+++ /trunk/BazaReklam/Classes/InvoiceProvider.cs (revision 611)
@@ -1,5 +1,7 @@
+using Baza_Reklam.Classes.Interfaces;
+
 namespace Baza_Reklam
 {
-    public class InvoiceProvider
+    public class InvoiceProvider : IInvoiceProvider
     {
         private string _city;
Index: /trunk/BazaReklam/Properties/AssemblyInfo.cs
===================================================================
--- /trunk/BazaReklam/Properties/AssemblyInfo.cs (revision 604)
+++ /trunk/BazaReklam/Properties/AssemblyInfo.cs (revision 611)
@@ -30,3 +30,3 @@
 //
 [assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.1.5")]
+[assembly: AssemblyFileVersion("1.1.6")]
Index: /trunk/BazaReklamSetup/BazaReklamSetup.vdproj
===================================================================
--- /trunk/BazaReklamSetup/BazaReklamSetup.vdproj (revision 609)
+++ /trunk/BazaReklamSetup/BazaReklamSetup.vdproj (revision 611)
@@ -725,6 +725,6 @@
         "Name" = "8:Microsoft Visual Studio"
         "ProductName" = "8:Baza Reklam"
-        "ProductCode" = "8:{DE903920-0572-4BA7-8623-E07D2868A25C}"
-        "PackageCode" = "8:{0E35FC2A-8DC5-4E25-8EF4-041C314C5E0B}"
+        "ProductCode" = "8:{E94CA729-B311-4DE5-BF21-DF116210CC02}"
+        "PackageCode" = "8:{724D56E2-C502-4EF3-9B3E-C5044DE7D117}"
         "UpgradeCode" = "8:{4E2DBBA4-3139-4790-8DDB-7AADFC963A7D}"
         "RestartWWWService" = "11:FALSE"
@@ -732,5 +732,5 @@
         "DetectNewerInstalledVersion" = "11:TRUE"
         "InstallAllUsers" = "11:TRUE"
-        "ProductVersion" = "8:1.1.5"
+        "ProductVersion" = "8:1.1.6"
         "Manufacturer" = "8:AACT"
         "ARPHELPTELEPHONE" = "8:"
Index: /trunk/BazaReklam.Updater/FormUpdate.cs
===================================================================
--- /trunk/BazaReklam.Updater/FormUpdate.cs (revision 597)
+++ /trunk/BazaReklam.Updater/FormUpdate.cs (revision 611)
@@ -99,5 +99,5 @@
             {
                 if (_args.Length < 2)
-                    throw new Exception("B³êdne wywo³anie programu!");
+                    throw new ApplicationException("B³êdne wywo³anie programu!");
 
                 _isBusy = true;
