Index: trunk/TruckExpoCDN/ExpoToCDNExport.cs
===================================================================
--- trunk/TruckExpoCDN/ExpoToCDNExport.cs (revision 427)
+++ trunk/TruckExpoCDN/ExpoToCDNExport.cs (revision 479)
@@ -1,9 +1,5 @@
 using System;
-using System.Collections.Generic;
-using System.Data;
 using System.Data.SqlClient;
-using System.Text;
 using System.Text.RegularExpressions;
-
 
 namespace ExportFaktur
@@ -12,16 +8,15 @@
     {
 
-		#region Fields (3) 
+        #region Fields (3)
 
         public CDNDataSet CDNDataset;
-        SqlConnection CDN_conn = new SqlConnection(ConnString.getConnString().CdnExpoConnStr);
-        SqlConnection truck_expo_conn = new SqlConnection(ConnString.getConnString().TruckExpoConnStr);
-
-		#endregion Fields 
-
-		#region Methods (10) 
-
-
-		// Public Methods (10) 
+        readonly SqlConnection CDN_conn = new SqlConnection(ConnString.CDNConnection);
+
+        #endregion Fields
+
+        #region Methods (10)
+
+
+        // Public Methods (10) 
 
         public void DodajElementyFaktury(EXPODataSet.FAKTURA_DETAILSDataTable table, CDNDataSet.TraNagRow naglowekFaktury)
@@ -57,6 +52,6 @@
                 {
                     pozycjaFaktury.TrE_KatID = naglowek.TrN_KatID;
-                }              
-                
+                }
+
                 pozycjaFaktury.TrE_TwrId = 1;
                 pozycjaFaktury.TrE_TwrNazwa = row.NAZWA_USLUGI + "   " + row.MIESIAC + "/" + row.ROK;
@@ -73,14 +68,14 @@
 
                 pozycjaFaktury.TrE_CenaT = row.NETTO; //Math.Abs(rsdet("netto"));
-              //  pozycjaFaktury.TrE_CenaT = row.CENA_JEDN; //Math.Abs(rsdet("netto"));
+                //  pozycjaFaktury.TrE_CenaT = row.CENA_JEDN; //Math.Abs(rsdet("netto"));
 
 
                 pozycjaFaktury.TrE_Cena0 = row.NETTO; //Math.Abs(netto);
                 //pozycjaFaktury.TrE_Cena0 = row.CENA_JEDN; //Math.Abs(netto);
-                pozycjaFaktury.TrE_Rabat = (decimal)row.UPUST_PR*100;
-               // pozycjaFaktury.TrE_Rabat = 0;                
+                pozycjaFaktury.TrE_Rabat = (decimal)row.UPUST_PR * 100;
+                // pozycjaFaktury.TrE_Rabat = 0;                
                 pozycjaFaktury.TrE_CenaW = row.NETTO; //Math.Abs(netto);
-                
-               
+
+
                 /*
                  * if rsdet("netto")<0 then
@@ -166,21 +161,21 @@
         public void DodajKlienta(EXPODataSet.KLIENCIRow klient)
         {
-            CDNDataSetTableAdapters.KontrahenciTableAdapter adapter = new ExportFaktur.CDNDataSetTableAdapters.KontrahenciTableAdapter();
+            CDNDataSetTableAdapters.KontrahenciTableAdapter adapter = new CDNDataSetTableAdapters.KontrahenciTableAdapter();
             adapter.Connection = CDN_conn;
 
-            adapter.FillByKnt_Kod(this.CDNDataset.Kontrahenci, klient.CustomerID.ToString());
+            adapter.FillByKnt_Kod(CDNDataset.Kontrahenci, klient.CustomerID.ToString());
 
             bool klientIstnieje;
             CDNDataSet.KontrahenciRow kontrahent;
 
-            if (this.CDNDataset.Kontrahenci.Count == 0)
+            if (CDNDataset.Kontrahenci.Count == 0)
             {
                 klientIstnieje = false;
-                kontrahent = (CDNDataSet.KontrahenciRow)this.CDNDataset.Kontrahenci.NewRow();
+                kontrahent = (CDNDataSet.KontrahenciRow)CDNDataset.Kontrahenci.NewRow();
             }
             else
             {
                 klientIstnieje = true;
-                kontrahent = this.CDNDataset.Kontrahenci[0];
+                kontrahent = CDNDataset.Kontrahenci[0];
             }
 
@@ -194,5 +189,5 @@
             kontrahent.Knt_Nazwa2 = klient.IsLastNameNull() ? "" : klient.LastName;
             kontrahent.Knt_Nazwa3 = klient.IsOrganizationNameNull() ? "" : klient.OrganizationName;
-            
+
             string kraj = "";
             if (!klient.IsCountryNull())
@@ -200,5 +195,5 @@
                 kraj = (klient.Country.Length > 40) ? klient.Country.Substring(0, 40) : klient.Country;
             }
-                        
+
             kontrahent.Knt_Kraj = kraj;
 
@@ -231,5 +226,5 @@
             kontrahent.Knt_Miasto = miasto;
             kontrahent.Knt_Poczta = miasto;
-            
+
             string kodPocztowy = "";
             if (!klient.IsPostalCodeNull())
@@ -238,12 +233,12 @@
             }
             kontrahent.Knt_KodPocztowy = kodPocztowy;
-            
+
             kontrahent.Knt_Adres2 = "";
 
             if (!klient.IsNipNull())
             {
-             //   kontrahent.Knt_NipKraj = PodajKrajNIP(klient.Nip);
-             //   kontrahent.Knt_NipE = PodajNumerNIP(klient.Nip);
-             //   kontrahent.Knt_Nip = PodajNumerNIP(klient.Nip);
+                //   kontrahent.Knt_NipKraj = PodajKrajNIP(klient.Nip);
+                //   kontrahent.Knt_NipE = PodajNumerNIP(klient.Nip);
+                //   kontrahent.Knt_Nip = PodajNumerNIP(klient.Nip);
                 if (klient.nipKraj == "" && klient.Country.Trim() == "Polska")
                 {
@@ -258,6 +253,6 @@
 
                 kontrahent.Knt_NipE = klient.Nip.Length > 13 ? klient.Nip.Substring(0, 13) : klient.Nip;
-                kontrahent.Knt_Nip = klient.Nip.Length > 13 ? klient.Nip.Substring(0,13) : klient.Nip;
-                
+                kontrahent.Knt_Nip = klient.Nip.Length > 13 ? klient.Nip.Substring(0, 13) : klient.Nip;
+
             }
             else
@@ -281,7 +276,7 @@
             }
             kontrahent.Knt_Email = email;
-            
+
             kontrahent.Knt_URL = "";
-          
+
 
             if (!klientIstnieje)
@@ -373,5 +368,5 @@
             if (!klientIstnieje)
             {
-                this.CDNDataset.Kontrahenci.AddKontrahenciRow(kontrahent);
+                CDNDataset.Kontrahenci.AddKontrahenciRow(kontrahent);
             }
 
@@ -381,10 +376,10 @@
         {
 
-            CDNDataSet.TraNagRow nowaFaktura = (CDNDataSet.TraNagRow)this.CDNDataset.TraNag.NewRow();
+            CDNDataSet.TraNagRow nowaFaktura = (CDNDataSet.TraNagRow)CDNDataset.TraNag.NewRow();
 
             //!!!!!!!!!!!!!!!
             //nowaFaktura.TrN_DDfId = 1;
 
-            CDNDataSetTableAdapters.DokDefinicjeTableAdapter adapter = new ExportFaktur.CDNDataSetTableAdapters.DokDefinicjeTableAdapter();
+            CDNDataSetTableAdapters.DokDefinicjeTableAdapter adapter = new CDNDataSetTableAdapters.DokDefinicjeTableAdapter();
             adapter.Connection = CDN_conn;
 
@@ -394,5 +389,5 @@
             nowaFaktura.TrN_TypDokumentu = 302;
 
-            nowaFaktura.TrN_NumerNr = Int32.Parse(EXPOfaktura.NUMER);
+            nowaFaktura.TrN_NumerNr = EXPOfaktura.NUMER;
             nowaFaktura.TrN_NumerString = "@numerS" + "/" + EXPOfaktura.NUMER_ROZ + "/" + EXPOfaktura.NUMER_ROK; //numerstring'              @P4 varchar(13)     '@numer/O/2007'
 
@@ -408,5 +403,5 @@
                 nowaFaktura.TrN_Korekta = 1;
                 nowaFaktura.TrN_Rodzaj = 302001;
-                int idkorekty = 0;
+                const int idkorekty = 0;
                 nowaFaktura.TrN_ZwrId = idkorekty;
             }
@@ -487,20 +482,13 @@
             nowaFaktura.TrN_RazemNetto = sumaNETTO;
             nowaFaktura.TrN_RazemVAT = VAT * sumaNETTO;
-            nowaFaktura.TrN_RazemBrutto = (decimal)((1 + VAT) * nowaFaktura.TrN_RazemNetto);
+            nowaFaktura.TrN_RazemBrutto = (1 + VAT) * nowaFaktura.TrN_RazemNetto;
             nowaFaktura.TrN_BlokadaPlatnosci = 0;
             nowaFaktura.TrN_MagZrdId = 1;
             nowaFaktura.TrN_TypNB = 1;
             nowaFaktura.TrN_Rabat = rabatProcent * 100;
-           //nowaFaktura.TrN_Rabat = 0;
-            
-
-            if (EXPOfaktura.IsPODPIS_ODEBRALNull())
-            {
-                nowaFaktura.TrN_Odebral = "zgodnie z owiadczeniem nabywcy";
-            }
-            else
-            {
-                nowaFaktura.TrN_Odebral = EXPOfaktura.PODPIS_ODEBRAL;
-            }
+            //nowaFaktura.TrN_Rabat = 0;
+
+
+            nowaFaktura.TrN_Odebral = EXPOfaktura.IsPODPIS_ODEBRALNull() ? "zgodnie z owiadczeniem nabywcy" : EXPOfaktura.PODPIS_ODEBRAL;
 
             nowaFaktura.TrN_Opis = EXPOfaktura.opis;
@@ -525,6 +513,6 @@
             nowaFaktura.TrN_PlatElemWalSys = 0;
 
-            nowaFaktura.TrN_RazemVATWal = VAT*100;
-            nowaFaktura.TrN_RazemBruttoWal = (decimal)((1 + VAT) * nowaFaktura.TrN_RazemNetto);
+            nowaFaktura.TrN_RazemVATWal = VAT * 100;
+            nowaFaktura.TrN_RazemBruttoWal = (1 + VAT) * nowaFaktura.TrN_RazemNetto;
             nowaFaktura.TrN_StaZalId = 1;
             nowaFaktura.TrN_StaModId = 1;
@@ -547,14 +535,14 @@
                 nowaFaktura.TrN_Export = 7;
                 nowaFaktura.TrN_WartoscZakupu = 0;
-                nowaFaktura.TrN_RazemVATWal = VAT * 100;            
+                nowaFaktura.TrN_RazemVATWal = VAT * 100;
                 nowaFaktura.TrN_RazemBruttoWal = (decimal)EXPOfaktura.waluta_brutto;
                 nowaFaktura.TrN_RazemNettoWal = ((decimal)EXPOfaktura.waluta_brutto / (1 + VAT));
-                nowaFaktura.TrN_Waluta =  EXPOfaktura.Iswaluta_mianoNull() ? "" : EXPOfaktura.waluta_miano;
-                nowaFaktura.TrN_KursL = EXPOfaktura.Iswaluta_kursNull()? 1M : (decimal)EXPOfaktura.waluta_kurs;
+                nowaFaktura.TrN_Waluta = EXPOfaktura.Iswaluta_mianoNull() ? "" : EXPOfaktura.waluta_miano;
+                nowaFaktura.TrN_KursL = EXPOfaktura.Iswaluta_kursNull() ? 1M : (decimal)EXPOfaktura.waluta_kurs;
                 nowaFaktura.TrN_KursM = 1;
                 nowaFaktura.TrN_KursNumer = 1;
             }
 
-            this.CDNDataset.TraNag.AddTraNagRow(nowaFaktura);
+            CDNDataset.TraNag.AddTraNagRow(nowaFaktura);
 
         }
@@ -562,5 +550,5 @@
         public void DodajVAT(CDNDataSet.TraNagRow naglowekFaktury, decimal sumaNetto, decimal stawkaVAT)
         {
-            CDNDataSet.TraVatRow nowyVat = (CDNDataSet.TraVatRow)this.CDNDataset.TraVat.NewRow();
+            CDNDataSet.TraVatRow nowyVat = (CDNDataSet.TraVatRow)CDNDataset.TraVat.NewRow();
 
             nowyVat.TrV_TrNID = naglowekFaktury.TrN_TrNID;
@@ -578,8 +566,8 @@
                 nowyVat.TrV_Flaga = 4;
                 nowyVat.TrV_VATWal = naglowekFaktury.TrN_RazemBruttoWal - naglowekFaktury.TrN_RazemNettoWal;
-                nowyVat.TrV_NettoWal = naglowekFaktury.TrN_RazemNettoWal;                
-            }
-
-            this.CDNDataset.TraVat.AddTraVatRow(nowyVat);
+                nowyVat.TrV_NettoWal = naglowekFaktury.TrN_RazemNettoWal;
+            }
+
+            CDNDataset.TraVat.AddTraVatRow(nowyVat);
         }
 
@@ -631,5 +619,5 @@
                             return 124;
                         case 5:
-                            return 125;                        
+                            return 125;
                     }
                     break;
@@ -647,16 +635,10 @@
                 return "PL";
             }
-            else
-            {
-                if ((nip.Length >= 2) && (!isNumeric(nip.Substring(0, 2))))
-                {
-                    return nip.Substring(0, 2);
-                }
-                else
-                {
-                    return "";
-                }
-                
-            }
+            if ((nip.Length >= 2) && (!isNumeric(nip.Substring(0, 2))))
+            {
+                return nip.Substring(0, 2);
+            }
+
+            return "";
         }
 
@@ -664,32 +646,22 @@
         {
             string nip = NIP.Replace(" ", "").Replace("-", "").Trim();
-    
+
             if (polskiNIP(nip))
             {
                 return nip.Length > 13 ? nip.Substring(0, 13) : nip;
             }
-            else
-            {
-                if ((nip.Length >= 2) && (!isNumeric(nip.Substring(0, 2))))
-                {
-                    return nip.Length > 15 ? nip.Substring(2, 13) : nip.Substring(2, nip.Length - 2);
-                }
-                else
-                {
-                    return nip.Length > 13 ? nip.Substring(0, 13) : nip;
-                }
-                
-            }
+            if ((nip.Length >= 2) && (!isNumeric(nip.Substring(0, 2))))
+            {
+                return nip.Length > 15 ? nip.Substring(2, 13) : nip.Substring(2, nip.Length - 2);
+            }
+            return nip.Length > 13 ? nip.Substring(0, 13) : nip;
         }
 
         public bool polskiNIP(string nip)
         {
-            int[] wagi = new int[] {6,5,7,2,3,4,5,6,7};
-                
-            string  shortNIP; 
-            int suma, iloczyn, kontrolny;
-	        suma=0;
-	        kontrolny=0;
-	        shortNIP = nip.Replace(" ", "").Replace("-", "").Trim();
+            int[] wagi = new int[] { 6, 5, 7, 2, 3, 4, 5, 6, 7 };
+
+            int suma = 0;
+            string shortNIP = nip.Replace(" ", "").Replace("-", "").Trim();
 
             if ((shortNIP.Length == 10) && isNumeric(shortNIP))
@@ -698,8 +670,8 @@
                 for (int i = 0; i <= 8; i++)
                 {
-                    iloczyn = Convert.ToInt32(shortNIP.Substring(i, 1)) * wagi[i];
+                    int iloczyn = Convert.ToInt32(shortNIP.Substring(i, 1)) * wagi[i];
                     suma = suma + iloczyn;
                 }
-                kontrolny = suma % 11;
+                int kontrolny = suma % 11;
 
                 if (kontrolny == Convert.ToInt32(shortNIP.Substring(shortNIP.Length - 1, 1)))
@@ -712,5 +684,5 @@
 
 
-		#endregion Methods 
+        #endregion Methods
 
     }
