Zbiór zmian 297

Pokaż
Ignoruj:
Data:
2009-02-05 10:26:58 (17 years ago)
Autor:
marek
Opis:

re #5

Lokalizacja:
trunk/BazaReklam
Pliki:
2 zmodyfikowane

Legenda:

Bez zmian
Dodane
Usunięte
  • trunk/BazaReklam/Classes/FakturaHelper.cs

    r296 r297  
     1using System; 
     2using System.Data; 
     3using System.Data.SqlClient; 
     4using Baza_Reklam.REKLAMADataSetTableAdapters; 
     5 
    16namespace Baza_Reklam 
    27{ 
     
    5257            } 
    5358        } 
     59 
     60        public static bool AddInvoice(REKLAMADataSet reklamaDataSet, FAKTURYTableAdapter fakturaAdapter, FAKTURA_DETAILSTableAdapter fakturaDetailsAdapter, WplatyTableAdapter wplataAdapter, REKLAMADataSet.FAKTURYRow fakturaRow) 
     61        { 
     62            SqlConnection conn; 
     63            SqlTransaction transaction = null; 
     64            try 
     65            { 
     66                conn = new SqlConnection(ConnString.getConnString().Value); 
     67                fakturaAdapter.Connection = conn; 
     68                fakturaDetailsAdapter.Connection = conn; 
     69                wplataAdapter.Connection = conn; 
     70 
     71                conn.Open(); 
     72 
     73                transaction = conn.BeginTransaction(); 
     74                fakturaAdapter.AttachTransaction(transaction); 
     75                fakturaDetailsAdapter.AttachTransaction(transaction); 
     76                wplataAdapter.AttachTransaction(transaction); 
     77 
     78                fakturaAdapter.Update(reklamaDataSet.FAKTURY); 
     79                fakturaDetailsAdapter.Update(reklamaDataSet.FAKTURA_DETAILS); 
     80                wplataAdapter.Update(reklamaDataSet.Wplaty); 
     81                transaction.Commit(); 
     82            } 
     83            catch (Exception) 
     84            { 
     85                if (transaction != null) transaction.Rollback(); 
     86                reklamaDataSet.FAKTURY.RemoveFAKTURYRow(fakturaRow); 
     87                throw; 
     88            } 
     89            return true; 
     90        } 
     91 
     92        public static void AddInvoiceDetails(REKLAMADataSet.FAKTURYRow newInvoice, REKLAMADataSet.FAKTURYRow clientInvoice, REKLAMADataSet.FAKTURA_DETAILSRow detailsRow, REKLAMADataSet.FAKTURA_DETAILSDataTable detailsTable) 
     93        { 
     94            REKLAMADataSet.FAKTURA_DETAILSRow row = detailsTable.NewFAKTURA_DETAILSRow(); 
     95 
     96            row.ROK = detailsRow.ROK; 
     97            row.MIESIAC = detailsRow.MIESIAC; 
     98            row.TYTUL = detailsRow.TYTUL; 
     99            row.NAZWA_USLUGI = clientInvoice != null ? clientInvoice.NUMER + "/" + clientInvoice.NUMER_ROZ + "/" + clientInvoice.NUMER_ROK + " | " + detailsRow.NAZWA_USLUGI : ""; 
     100            row.reklamaId = detailsRow.reklamaId; 
     101            row.NR_WYDANIA = detailsRow.NR_WYDANIA; 
     102 
     103            row.CENA_JEDN = detailsRow.CENA_JEDN; 
     104            row.ILOSC = 1; 
     105            row.JM = "szt."; 
     106 
     107            row.UPUST_NETTO = detailsRow.UPUST_NETTO; 
     108            row.UPUST_PR = detailsRow.UPUST_PR; 
     109            row.NETTO = detailsRow.NETTO; 
     110            row.S_VAT = VatHelper.PL22; 
     111            row.VAT = (decimal)VatHelper.PL22 * detailsRow.NETTO; 
     112            row.BRUTTO = detailsRow.NETTO * (decimal)(1 + VatHelper.PL22); 
     113 
     114            row.TYP = 2; 
     115            row.PODTYP = 1; 
     116            row.ID_FAKTURY = newInvoice.ID_FAKTURY; 
     117 
     118            row.wyroznienie = (!detailsRow.IswyroznienieNull() && detailsRow.wyroznienie); 
     119 
     120            detailsTable.AddFAKTURA_DETAILSRow(row); 
     121        } 
     122 
     123        public static string GetNazwaUslugiPozKat(REKLAMADataSet.FAKTURYRow faktura, REKLAMADataSet.FAKTURA_DETAILSRow pozycjaFaktury) 
     124        { 
     125            if (faktura == null) return string.Empty; 
     126 
     127            return faktura.NUMER + "/" + faktura.NUMER_ROZ + "/" + faktura.NUMER_ROK + " | " + pozycjaFaktury.NAZWA_USLUGI; 
     128        } 
    54129    } 
    55130} 
  • trunk/BazaReklam/FakturowaniePoznanKatowice.cs

    r296 r297  
    8686            try 
    8787            { 
    88  
    8988                SLOWNIKDataSet.AGENCJERow agencja = GetAgency(agencjaListBox.SelectedItem.ToString()); 
    9089 
     
    9392                                                                                  (int)nrTygodniaUpDown.Value, 
    9493                                                                                  agencja.Id_agencji); 
    95                 if(fakturyDataTable.Rows.Count<= 0) 
     94                if (fakturyDataTable.Rows.Count <= 0) 
    9695                { 
    9796                    Cursor = Cursors.Default; 
     
    10099                } 
    101100 
    102                 REKLAMADataSet.FAKTURA_DETAILSDataTable fakturaDetailsDataTable = GetFakturaDetailsRows(dtpZmianaDaty.Value.Year, 
    103                                                                                                         dtpZmianaDaty.Value.Month, 
    104                                                                                                         (int)nrTygodniaUpDown.Value, 
    105                                                                                                         agencja.Id_agencji); 
    106                  
     101                REKLAMADataSet.FAKTURA_DETAILSDataTable fakturaDetailsDataTable = 
     102                    GetFakturaDetailsRows(dtpZmianaDaty.Value.Year, 
     103                                          dtpZmianaDaty.Value.Month, 
     104                                          (int)nrTygodniaUpDown.Value, 
     105                                          agencja.Id_agencji); 
     106 
    107107                REKLAMADataSet.FAKTURYRow naglowekFaktury = utworzNaglowekFaktury(GetClient(agencjaListBox.SelectedItem.ToString()), 
    108108                                                                                  agencja, 
    109109                                                                                  FakturaHelper.PaymentType.Transfer); 
    110  
     110                     
    111111                rEKLAMADataSet.FAKTURY.AddFAKTURYRow(naglowekFaktury); 
    112112                utworzPozycjeFaktury(naglowekFaktury, fakturyDataTable, fakturaDetailsDataTable); 
    113113                dodajWplate(naglowekFaktury); 
    114114 
    115                 SqlConnection conn = new SqlConnection(ConnString.getConnString().Value); 
    116  
    117                 fAKTURYTableAdapter.Connection = conn; 
    118                 fakturA_DETAILSTableAdapter.Connection = conn; 
    119                 wplatyTableAdapter.Connection = conn; 
    120  
    121                 conn.Open(); 
    122  
    123                 SqlTransaction transaction = conn.BeginTransaction(); 
    124                 fAKTURYTableAdapter.AttachTransaction(transaction); 
    125                 fakturA_DETAILSTableAdapter.AttachTransaction(transaction); 
    126                 wplatyTableAdapter.AttachTransaction(transaction); 
    127  
    128                 try 
    129                 { 
    130                     fAKTURYTableAdapter.Update(rEKLAMADataSet.FAKTURY); 
    131                     fakturA_DETAILSTableAdapter.Update(rEKLAMADataSet.FAKTURA_DETAILS); 
    132                     wplatyTableAdapter.Update(rEKLAMADataSet.Wplaty); 
    133                     transaction.Commit(); 
    134                     dtpZmianaDaty.Value = DateTime.Today; 
    135                 } 
    136                 catch (Exception) 
    137                 { 
    138                     transaction.Rollback(); 
    139                     conn.Close(); 
    140                     rEKLAMADataSet.FAKTURA_DETAILS.Clear(); 
    141                     rEKLAMADataSet.FAKTURY.RemoveFAKTURYRow(naglowekFaktury); 
    142                     fAKTURYBindingSource.ResetBindings(false); 
    143                     fAKTURYDataGridView.Refresh(); 
    144                     throw; 
    145                 } 
    146             } 
    147             catch (Exception e2) 
    148             { 
    149                 MessageBox.Show("Wyst¹pi³ b³¹d: \n" + e2); 
     115                FakturaHelper.AddInvoice(rEKLAMADataSet, 
     116                                         fAKTURYTableAdapter, 
     117                                         fakturA_DETAILSTableAdapter, 
     118                                         wplatyTableAdapter, 
     119                                         naglowekFaktury); 
     120                 
     121                dtpZmianaDaty.Value = DateTime.Today; 
     122            } 
     123            catch (Exception ex) 
     124            { 
     125                MessageBox.Show("Wyst¹pi³ b³¹d: \n" + ex); 
    150126            } 
    151127            finally 
    152128            { 
     129                Cursor = Cursors.Default; 
    153130                rEKLAMADataSet.FAKTURA_DETAILS.Clear(); 
    154131                rEKLAMADataSet.Wplaty.Clear(); 
     
    157134                fAKTURYTableAdapter.FillByKodAgenta(rEKLAMADataSet.FAKTURY, agencjaListBox.SelectedItem.ToString()); 
    158135                fAKTURYDataGridView.Refresh(); 
    159             } 
     136                 
     137                if (fAKTURYTableAdapter.Connection != null && 
     138                    fAKTURYTableAdapter.Connection.State == ConnectionState.Open) 
     139                { 
     140                    fAKTURYTableAdapter.Connection.Close(); 
     141                    fAKTURYTableAdapter.Connection.Dispose(); 
     142                } 
     143            } 
     144        } 
     145 
     146        private REKLAMADataSet.FAKTURYRow utworzNaglowekFaktury(REKLAMADataSet.KLIENCIRow klientAgencja, 
     147                                                                SLOWNIKDataSet.AGENCJERow agencja, 
     148                                                                FakturaHelper.PaymentType paymentType) 
     149        { 
     150            REKLAMADataSet.FAKTURYRow naglowekFaktury = (REKLAMADataSet.FAKTURYRow) rEKLAMADataSet.FAKTURY.NewRow(); 
     151 
     152            naglowekFaktury.NUMER_ROZ = agencjaListBox.SelectedItem.ToString(); 
     153            naglowekFaktury.NUMER = Utils.numerNowejFaktury(naglowekFaktury.NUMER_ROZ, DateTime.Today.Year); 
     154            naglowekFaktury.NUMER_ROK = DateTime.Today.Year; 
     155 
     156            naglowekFaktury.DATA_WYSTAWIENIA = dtpZmianaDaty.Value != DateTime.Today ? dtpZmianaDaty.Value : DateTime.Today; 
     157 
     158            naglowekFaktury.idZamowienia = agencja.Id_agencji == (int)FakturaHelper.OfficeId.Poznan ?  
     159                                           (int)FakturaHelper.OrderId.Poznan : (int)FakturaHelper.OrderId.Katowice; 
     160 
     161            naglowekFaktury.ID_SPRZEDAWCY = agencja.Id_agencji; 
     162 
     163            naglowekFaktury.EKSPORT = false; 
     164 
     165            naglowekFaktury.MIEJSCOWOSC_WYSTAWIENIA = agencjaRedakcja.miasto; 
     166            naglowekFaktury.SPRZEDAWCA_ADRES = agencjaRedakcja.Adres_Fk; 
     167            naglowekFaktury.SPRZEDAWCA_NIP = agencjaRedakcja.NIP; 
     168 
     169            naglowekFaktury.PODPIS_WYSTAWIL = string.Empty; 
     170            naglowekFaktury.DATA_SPRZEDAZY = naglowekFaktury.DATA_WYSTAWIENIA; 
     171 
     172            naglowekFaktury.ID_NABYWCY = klientAgencja.CustomerID; 
     173            naglowekFaktury.NABYWCA_ADRES = klientAgencja.Adres_Fkatura; 
     174            naglowekFaktury.NABYWCA_NIP = klientAgencja.Nip; 
     175            naglowekFaktury.opis = string.Empty; 
     176 
     177            naglowekFaktury.SPOSOB_ZAPLATY = FakturaHelper.GetPaymentType((int) paymentType); 
     178 
     179            naglowekFaktury.TERMIN_ZAPLATY = naglowekFaktury.DATA_SPRZEDAZY.AddDays(14); 
     180            naglowekFaktury.ZAPLACONO = false; 
     181 
     182            naglowekFaktury.FAKTURA_TYP = 2; 
     183            naglowekFaktury.FAKTURA_PODTYP = 1; 
     184 
     185            naglowekFaktury.ID_KONTA = Convert.ToInt16(konto.id); 
     186 
     187            naglowekFaktury.EndEdit(); 
     188            return naglowekFaktury; 
     189        } 
     190 
     191        private void utworzPozycjeFaktury(REKLAMADataSet.FAKTURYRow naglowekFaktury, REKLAMADataSet.FAKTURYDataTable naglowkiFakturDlaKlientow, REKLAMADataSet.FAKTURA_DETAILSDataTable pozycjeFakturDlaKlientow) 
     192        { 
     193 
     194            foreach (REKLAMADataSet.FAKTURA_DETAILSRow pozycjaFaktury in pozycjeFakturDlaKlientow) 
     195            { 
     196 
     197                REKLAMADataSet.FAKTURYRow faktura = naglowkiFakturDlaKlientow.FindByID_FAKTURY(pozycjaFaktury.ID_FAKTURY); 
     198 
     199                FakturaHelper.AddInvoiceDetails(naglowekFaktury, faktura, pozycjaFaktury, rEKLAMADataSet.FAKTURA_DETAILS); 
     200            } 
     201        } 
     202 
     203        private REKLAMADataSet.FAKTURA_DETAILSDataTable GetFakturaDetailsRows(int year, int month, int week, int sellerId) 
     204        { 
     205            return fakturA_DETAILSTableAdapter.GetDataByNrTygodniaWRoku(year, week, sellerId, month); 
     206        } 
     207 
     208        private REKLAMADataSet.FAKTURYDataTable GetFakturaRows(int year, int month, int week, int sellerId) 
     209        { 
     210            return fAKTURYTableAdapter.GetDataByNrTygodniaWRoku(year, week, sellerId, month); 
     211 
     212        } 
     213 
     214        private void dodajWplate(REKLAMADataSet.FAKTURYRow naglowekFaktury) 
     215        { 
     216            REKLAMADataSet.WplatyRow wplata = rEKLAMADataSet.Wplaty.NewWplatyRow(); 
     217            wplata.idFaktury = naglowekFaktury.ID_FAKTURY; 
     218 
     219            wplata.idZamowienia = naglowekFaktury.ID_SPRZEDAWCY == (int) FakturaHelper.OfficeId.Poznan 
     220                                      ? (int) FakturaHelper.OrderId.Poznan 
     221                                      : (int) FakturaHelper.OrderId.Katowice; 
     222        } 
     223 
     224        private void wydrukButton_Click(object sender, EventArgs e) 
     225        { 
     226            if (fAKTURYBindingSource.Current != null) 
     227            { 
     228                REKLAMADataSet.FAKTURYRow row = 
     229                    (REKLAMADataSet.FAKTURYRow) 
     230                    ((DataRowView) fAKTURYBindingSource.Current).Row; 
     231 
     232                if (row.IsidFakturyKorektaNull()) 
     233                { 
     234                    FactureViewer fv = new FactureViewer(row.ID_FAKTURY, false); 
     235                    fv.ShowDialog(); 
     236                } 
     237                else 
     238                { 
     239                    FactureViewer fv = new FactureViewer(row.ID_FAKTURY, row.idFakturyVAT, row.idFakturyKorekta); 
     240                    fv.ShowDialog(); 
     241                } 
     242            } 
     243        } 
     244 
     245 
     246        private void usunFaktureButton_Click(object sender, EventArgs e) 
     247        { 
     248            if (fAKTURYBindingSource.Current == null) return; 
     249 
     250            DialogResult dialogResult = MessageBox.Show("Czy na pewno chcesz usun¹æ fakturê?", 
     251                                                        "Faktura - usuwanie", 
     252                                                        MessageBoxButtons.YesNo, 
     253                                                        MessageBoxIcon.Question); 
     254            if (dialogResult != DialogResult.Yes) return; 
     255 
     256            Cursor = Cursors.WaitCursor; 
     257 
     258            REKLAMADataSet.FAKTURYRow faktura = (REKLAMADataSet.FAKTURYRow) 
     259                                                ((DataRowView) fAKTURYBindingSource.Current).Row; 
     260 
     261            string kod = faktura.NUMER_ROZ; 
     262 
     263            if (faktura.KOREKTA) 
     264            { 
     265                int i = fAKTURYBindingSource.Find("idFakturyKorekta", faktura.ID_FAKTURY); 
     266                if (i > -1) 
     267                { 
     268                    MessageBox.Show("Nie mo¿na usun¹æ faktury"); 
     269                } 
     270                else 
     271                { 
     272                    usunKorekte(faktura); 
     273                } 
     274            } 
     275            else 
     276            { 
     277                usunFakture(faktura); 
     278            } 
     279 
     280            fAKTURYTableAdapter.FillByKodAgenta(rEKLAMADataSet.FAKTURY, kod); 
     281            fAKTURYDataGridView.Refresh(); 
    160282 
    161283            Cursor = Cursors.Default; 
    162284        } 
    163285 
     286 
     287        private void usunFakture(REKLAMADataSet.FAKTURYRow faktura) 
     288        { 
     289            int idFakt = faktura.ID_FAKTURY; 
     290 
     291            SqlConnection conn = new SqlConnection(ConnString.getConnString().Value); 
     292 
     293            fAKTURYTableAdapter.Connection = conn; 
     294            fakturA_DETAILSTableAdapter.Connection = conn; 
     295            wplatyTableAdapter.Connection = conn; 
     296 
     297            conn.Open(); 
     298            SqlTransaction transaction = conn.BeginTransaction(); 
     299 
     300            fAKTURYTableAdapter.AttachTransaction(transaction); 
     301            fakturA_DETAILSTableAdapter.AttachTransaction(transaction); 
     302            wplatyTableAdapter.AttachTransaction(transaction); 
     303 
     304            try 
     305            { 
     306                fAKTURYTableAdapter.Delete(idFakt); 
     307                fakturA_DETAILSTableAdapter.Delete(idFakt); 
     308                wplatyTableAdapter.Delete(idFakt); 
     309 
     310                transaction.Commit(); 
     311            } 
     312            catch (Exception) 
     313            { 
     314                transaction.Rollback(); 
     315            } 
     316            finally 
     317            { 
     318                conn.Close(); 
     319            } 
     320        } 
     321 
     322 
     323        #region Korekta 
     324 
    164325        private void korektaButton_Click(object sender, EventArgs e) 
    165326        { 
     
    168329                Cursor = Cursors.WaitCursor; 
    169330 
    170                 DataRowView row = (DataRowView) fAKTURYBindingSource.Current; 
    171                 REKLAMADataSet.FAKTURYRow faktura = (REKLAMADataSet.FAKTURYRow) row.Row; 
     331                DataRowView row = (DataRowView)fAKTURYBindingSource.Current; 
     332                REKLAMADataSet.FAKTURYRow faktura = (REKLAMADataSet.FAKTURYRow)row.Row; 
    172333 
    173334                if (faktura.KOREKTA) 
     
    242403        } 
    243404 
     405 
    244406        private REKLAMADataSet.FAKTURYRow utworzNaglowekKorekty(REKLAMADataSet.FAKTURYRow faktura) 
    245407        { 
     
    288450 
    289451 
    290         private REKLAMADataSet.FAKTURYRow utworzNaglowekFaktury(REKLAMADataSet.KLIENCIRow klientAgencja, 
    291                                                                 SLOWNIKDataSet.AGENCJERow agencja, 
    292                                                                 FakturaHelper.PaymentType paymentType) 
    293         { 
    294             REKLAMADataSet.FAKTURYRow naglowekFaktury = (REKLAMADataSet.FAKTURYRow) rEKLAMADataSet.FAKTURY.NewRow(); 
    295  
    296             naglowekFaktury.NUMER_ROZ = agencjaListBox.SelectedItem.ToString(); 
    297             naglowekFaktury.NUMER = Utils.numerNowejFaktury(naglowekFaktury.NUMER_ROZ, DateTime.Today.Year); 
    298             naglowekFaktury.NUMER_ROK = DateTime.Today.Year; 
    299             naglowekFaktury.DATA_WYSTAWIENIA = DateTime.Today; 
    300  
    301             if (dtpZmianaDaty.Value != DateTime.Today) 
    302             { 
    303                 naglowekFaktury.DATA_WYSTAWIENIA = dtpZmianaDaty.Value; 
    304             } 
    305  
    306             naglowekFaktury.idZamowienia = agencja.Id_agencji == (int)FakturaHelper.OfficeId.Poznan ?  
    307                                            (int)FakturaHelper.OrderId.Poznan : (int)FakturaHelper.OrderId.Katowice; 
    308  
    309             naglowekFaktury.ID_SPRZEDAWCY = agencja.Id_agencji; 
    310  
    311             naglowekFaktury.EKSPORT = false; 
    312  
    313             naglowekFaktury.MIEJSCOWOSC_WYSTAWIENIA = agencjaRedakcja.miasto; 
    314             naglowekFaktury.SPRZEDAWCA_ADRES = agencjaRedakcja.Adres_Fk; 
    315             naglowekFaktury.SPRZEDAWCA_NIP = agencjaRedakcja.NIP; 
    316  
    317             naglowekFaktury.PODPIS_WYSTAWIL = string.Empty; 
    318             naglowekFaktury.DATA_SPRZEDAZY = naglowekFaktury.DATA_WYSTAWIENIA; 
    319  
    320             naglowekFaktury.ID_NABYWCY = klientAgencja.CustomerID; 
    321             naglowekFaktury.NABYWCA_ADRES = klientAgencja.Adres_Fkatura; 
    322             naglowekFaktury.NABYWCA_NIP = klientAgencja.Nip; 
    323             naglowekFaktury.opis = string.Empty; 
    324  
    325             naglowekFaktury.SPOSOB_ZAPLATY = FakturaHelper.GetPaymentType((int) paymentType); 
    326  
    327             naglowekFaktury.TERMIN_ZAPLATY = naglowekFaktury.DATA_SPRZEDAZY.AddDays(14); 
    328             naglowekFaktury.ZAPLACONO = false; 
    329  
    330             naglowekFaktury.FAKTURA_TYP = 2; 
    331             naglowekFaktury.FAKTURA_PODTYP = 1; 
    332  
    333             naglowekFaktury.ID_KONTA = Convert.ToInt16(konto.id); 
    334  
    335             naglowekFaktury.EndEdit(); 
    336             return naglowekFaktury; 
    337         } 
    338  
    339         private void utworzPozycjeFaktury(REKLAMADataSet.FAKTURYRow naglowekFaktury, REKLAMADataSet.FAKTURYDataTable naglowkiFakturDlaKlientow, REKLAMADataSet.FAKTURA_DETAILSDataTable pozycjeFakturDlaKlientow) 
    340         { 
    341  
    342             foreach (REKLAMADataSet.FAKTURA_DETAILSRow pozycjaFaktury in pozycjeFakturDlaKlientow) 
    343             { 
    344  
    345                 REKLAMADataSet.FAKTURYRow faktura = naglowkiFakturDlaKlientow.FindByID_FAKTURY(pozycjaFaktury.ID_FAKTURY); 
    346  
    347                 AddFakturaDetails(naglowekFaktury, faktura, pozycjaFaktury, rEKLAMADataSet.FAKTURA_DETAILS); 
    348             } 
    349         } 
    350  
    351         private REKLAMADataSet.FAKTURA_DETAILSDataTable GetFakturaDetailsRows(int year, int month, int week, int sellerId) 
    352         { 
    353             return fakturA_DETAILSTableAdapter.GetDataByNrTygodniaWRoku(year, week, sellerId, month); 
    354         } 
    355  
    356         private REKLAMADataSet.FAKTURYDataTable GetFakturaRows(int year, int month, int week, int sellerId) 
    357         { 
    358             return fAKTURYTableAdapter.GetDataByNrTygodniaWRoku(year, week, sellerId, month); 
    359  
    360         } 
    361  
    362         private void AddFakturaDetails(REKLAMADataSet.FAKTURYRow newInvoice, REKLAMADataSet.FAKTURYRow clientInvoice, REKLAMADataSet.FAKTURA_DETAILSRow detailsRow, REKLAMADataSet.FAKTURA_DETAILSDataTable detailsTable) 
    363         { 
    364             REKLAMADataSet.FAKTURA_DETAILSRow row = detailsTable.NewFAKTURA_DETAILSRow(); 
    365  
    366             row.ROK = detailsRow.ROK; 
    367             row.MIESIAC = detailsRow.MIESIAC; 
    368             row.TYTUL = detailsRow.TYTUL; 
    369             row.NAZWA_USLUGI = clientInvoice != null ? clientInvoice.NUMER + "/" + clientInvoice.NUMER_ROZ + "/" + clientInvoice.NUMER_ROK + " | " + detailsRow.NAZWA_USLUGI : ""; 
    370             row.reklamaId = detailsRow.reklamaId; 
    371             row.NR_WYDANIA = detailsRow.NR_WYDANIA; 
    372  
    373             row.CENA_JEDN = detailsRow.CENA_JEDN; 
    374             row.ILOSC = 1; 
    375             row.JM = "szt."; 
    376  
    377             row.UPUST_NETTO = detailsRow.UPUST_NETTO; 
    378             row.UPUST_PR = detailsRow.UPUST_PR; 
    379             row.NETTO = detailsRow.NETTO; 
    380             row.S_VAT = VatHelper.PL22; 
    381             row.VAT = (decimal)VatHelper.PL22 * detailsRow.NETTO; 
    382             row.BRUTTO = detailsRow.NETTO * (decimal)(1 + VatHelper.PL22); 
    383  
    384             row.TYP = 2; 
    385             row.PODTYP = 1; 
    386             row.ID_FAKTURY = newInvoice.ID_FAKTURY; 
    387  
    388             row.wyroznienie = (!detailsRow.IswyroznienieNull() && detailsRow.wyroznienie); 
    389  
    390             detailsTable.AddFAKTURA_DETAILSRow(row); 
    391  
    392         } 
    393  
    394452        private void utworzPozycjeFakturyKorekty(REKLAMADataSet.FAKTURYRow naglowekFaktury) 
    395453        { 
     
    419477                fakturaDetailsRow.MIESIAC = pozycjaFaktury.MIESIAC; 
    420478                fakturaDetailsRow.TYTUL = pozycjaFaktury.TYTUL; 
    421                 fakturaDetailsRow.NAZWA_USLUGI = GetNazwaUslugiPozKat(faktura, pozycjaFaktury); 
     479                fakturaDetailsRow.NAZWA_USLUGI = FakturaHelper.GetNazwaUslugiPozKat(faktura, pozycjaFaktury); 
    422480                fakturaDetailsRow.reklamaId = pozycjaFaktury.reklamaId; 
    423481                fakturaDetailsRow.NR_WYDANIA = pozycjaFaktury.NR_WYDANIA; 
     
    451509        } 
    452510 
    453         private string GetNazwaUslugiPozKat(REKLAMADataSet.FAKTURYRow faktura, REKLAMADataSet.FAKTURA_DETAILSRow pozycjaFaktury) 
    454         { 
    455             if (faktura == null) return string.Empty; 
    456  
    457             return faktura.NUMER + "/" + faktura.NUMER_ROZ + "/" + faktura.NUMER_ROK + " | " + pozycjaFaktury.NAZWA_USLUGI; 
    458         } 
    459  
    460  
    461         private void dodajWplate(REKLAMADataSet.FAKTURYRow naglowekFaktury) 
    462         { 
    463             REKLAMADataSet.WplatyRow wplata = rEKLAMADataSet.Wplaty.NewWplatyRow(); 
    464             wplata.idFaktury = naglowekFaktury.ID_FAKTURY; 
    465  
    466             if (naglowekFaktury.ID_SPRZEDAWCY == (int) FakturaHelper.OfficeId.Poznan) 
    467                 wplata.idZamowienia = (int) FakturaHelper.OrderId.Poznan; 
    468             else 
    469                 wplata.idZamowienia = (int) FakturaHelper.OrderId.Katowice; 
    470         } 
    471  
    472         private void wydrukButton_Click(object sender, EventArgs e) 
    473         { 
    474             if (fAKTURYBindingSource.Current != null) 
    475             { 
    476                 REKLAMADataSet.FAKTURYRow row = 
    477                     (REKLAMADataSet.FAKTURYRow) 
    478                     ((DataRowView) fAKTURYBindingSource.Current).Row; 
    479  
    480                 if (row.IsidFakturyKorektaNull()) 
    481                 { 
    482                     FactureViewer fv = new FactureViewer(row.ID_FAKTURY, false); 
    483                     fv.ShowDialog(); 
    484                 } 
    485                 else 
    486                 { 
    487                     FactureViewer fv = new FactureViewer(row.ID_FAKTURY, row.idFakturyVAT, row.idFakturyKorekta); 
    488                     fv.ShowDialog(); 
    489                 } 
    490             } 
    491         } 
    492  
    493         private void usunFaktureButton_Click(object sender, EventArgs e) 
    494         { 
    495             if (fAKTURYBindingSource.Current == null) return; 
    496  
    497             DialogResult dialogResult = MessageBox.Show("Czy na pewno chcesz usun¹æ fakturê?", 
    498                                                         "Faktura - usuwanie", 
    499                                                         MessageBoxButtons.YesNo, 
    500                                                         MessageBoxIcon.Question); 
    501             if (dialogResult != DialogResult.Yes) return; 
    502  
    503             Cursor = Cursors.WaitCursor; 
    504  
    505             REKLAMADataSet.FAKTURYRow faktura = (REKLAMADataSet.FAKTURYRow) 
    506                                                 ((DataRowView) fAKTURYBindingSource.Current).Row; 
    507  
    508             string kod = faktura.NUMER_ROZ; 
    509  
    510             if (faktura.KOREKTA) 
    511             { 
    512                 int i = fAKTURYBindingSource.Find("idFakturyKorekta", faktura.ID_FAKTURY); 
    513                 if (i > -1) 
    514                 { 
    515                     MessageBox.Show("Nie mo¿na usun¹æ faktury"); 
    516                 } 
    517                 else 
    518                 { 
    519                     usunKorekte(faktura); 
    520                 } 
    521             } 
    522             else 
    523             { 
    524                 usunFakture(faktura); 
    525             } 
    526  
    527             fAKTURYTableAdapter.FillByKodAgenta(rEKLAMADataSet.FAKTURY, kod); 
    528             fAKTURYDataGridView.Refresh(); 
    529  
    530             Cursor = Cursors.Default; 
    531         } 
    532511 
    533512        private void usunKorekte(REKLAMADataSet.FAKTURYRow korekta) 
     
    540519 
    541520            REKLAMADataSet.FAKTURYRow korygowanaFaktura = (REKLAMADataSet.FAKTURYRow) 
    542                                                           ((DataRowView) fAKTURYBindingSource.List[i]).Row; 
     521                                                          ((DataRowView)fAKTURYBindingSource.List[i]).Row; 
    543522 
    544523            int j = fAKTURYBindingSource.Find("ID_FAKTURY", idKorygowanejFaktury); 
     
    547526            { 
    548527                REKLAMADataSet.FAKTURYRow poprzedniaKorekta = (REKLAMADataSet.FAKTURYRow) 
    549                                                               ((DataRowView) fAKTURYBindingSource.List[j]).Row; 
     528                                                              ((DataRowView)fAKTURYBindingSource.List[j]).Row; 
    550529 
    551530                korygowanaFaktura.ID_FK_KOR = poprzedniaKorekta.ID_FAKTURY; 
     
    589568        } 
    590569 
    591         private void usunFakture(REKLAMADataSet.FAKTURYRow faktura) 
    592         { 
    593             int idFakt = faktura.ID_FAKTURY; 
    594  
    595             SqlConnection conn = new SqlConnection(ConnString.getConnString().Value); 
    596  
    597             fAKTURYTableAdapter.Connection = conn; 
    598             fakturA_DETAILSTableAdapter.Connection = conn; 
    599             wplatyTableAdapter.Connection = conn; 
    600  
    601             conn.Open(); 
    602             SqlTransaction transaction = conn.BeginTransaction(); 
    603  
    604             fAKTURYTableAdapter.AttachTransaction(transaction); 
    605             fakturA_DETAILSTableAdapter.AttachTransaction(transaction); 
    606             wplatyTableAdapter.AttachTransaction(transaction); 
    607  
    608             try 
    609             { 
    610                 fAKTURYTableAdapter.Delete(idFakt); 
    611                 fakturA_DETAILSTableAdapter.Delete(idFakt); 
    612                 wplatyTableAdapter.Delete(idFakt); 
    613  
    614                 transaction.Commit(); 
    615             } 
    616             catch (Exception) 
    617             { 
    618                 transaction.Rollback(); 
    619             } 
    620             finally 
    621             { 
    622                 conn.Close(); 
    623             } 
    624         } 
     570        #endregion 
     571 
    625572    } 
    626573}