Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component } from '@angular/core';
  2. declare var jquery:any;
  3. declare var $ :any;
  4.  
  5. @Component({
  6.   selector: 'app-root',
  7.   templateUrl: './app.component.html',
  8.   styleUrls: ['./app.component.css']
  9. })
  10. export class AppComponent {
  11.   title = "Fakturky";
  12.   towary: Array<Towar> = [];
  13.   faktury: Array<Faktura> = [];
  14.   towar: string = "";
  15.   faktura: string = "";
  16.   listaTowarow: Array<Towar> = [];
  17.   iloscTowarow: number = 0;
  18.   iloscFaktur: number = 0;
  19.  
  20.   DodajTowar () {
  21.     let juzIstnieje = false;
  22.     for (let i=0; i<this.towary.length; i++) {
  23.       if (this.towary[i].nazwa === this.towar) {
  24.         juzIstnieje = true;
  25.         break;
  26.       }
  27.     }
  28.     if (juzIstnieje)
  29.       return;
  30.     else if (this.towar!="") {
  31.       this.iloscTowarow++;
  32.       this.towary.push(new Towar(this.iloscTowarow,this.towar,new Czlowiek("Patryk","Komar"),[]));
  33.     }
  34.     this.towar = "";
  35.   }
  36.  
  37.   UsunTowar (towar: Towar): void {
  38.     let indeksik = -1;
  39.     for (let i=0; i<this.towary.length; i++) {
  40.       if (this.towary[i].nazwa === towar.nazwa) {
  41.         indeksik = i;
  42.         break; }
  43.     }
  44.     if (indeksik === -1)
  45.       return;
  46.     else {
  47.       this.towary.splice(indeksik,1);
  48.     }
  49.   }
  50.  
  51.   DodajFakture () {
  52.     let juzIstnieje = false;
  53.     for (let i=0; i<this.faktury.length; i++) {
  54.       if (this.faktury[i].nazwa === this.faktura) {
  55.         juzIstnieje = true;
  56.         break;
  57.       }
  58.     }
  59.     if (juzIstnieje)
  60.       return;
  61.     else if (this.faktura!="") {
  62.       this.iloscFaktur++;
  63.       const nowaFakturka = new Faktura(this.iloscFaktur,this.faktura,this.listaTowarow);
  64.       this.faktury.push(nowaFakturka);
  65.       for (let k=0; k<nowaFakturka.towary.length; k++) {
  66.         nowaFakturka.towary[k].fakturky.push(nowaFakturka);
  67.       }
  68.     }
  69.     this.faktura = "";
  70.     console.log(this.listaTowarow);
  71.     this.listaTowarow = [];
  72.   }
  73.  
  74.   UsunFakture (faktura: Faktura): void {
  75.     let indeksik = -1;
  76.     for (let i=0; i<this.faktury.length; i++) {
  77.       if (this.faktury[i].nazwa === faktura.nazwa) {
  78.         indeksik = i;
  79.         break; }
  80.     }
  81.     if (indeksik === -1)
  82.       return;
  83.     else {
  84.       this.faktury.splice(indeksik,1);
  85.     }
  86.   }
  87.  
  88.   UpdateListyTowarow () {
  89.     let thisListaTowarow = this.listaTowarow;
  90.     let thisTowary = this.towary;
  91.     let nowaLista = [];
  92.     const lista = $('select option').each(function() {
  93.       if(this.selected) {
  94.         const ID = this.id.replace('towarNr','');
  95.         for (let i=0; i<thisTowary.length; i++) {
  96.           if (thisTowary[i].numer == ID) {
  97.             nowaLista.push(thisTowary[i]);
  98.           }
  99.         }
  100.       }
  101.     });
  102.  
  103.     this.listaTowarow = nowaLista;
  104.      
  105.  
  106.     /*
  107.     for (let i=1; i<=this.iloscTowarow; i++) {
  108.       const ID = "#"+"towarNr"+i;
  109.       const element = $(ID);
  110.       console.log(element);
  111.       if (element!=null) {
  112.         if (element.selected) {
  113.           console.log("TUTAJ2");
  114.           this.towary.forEach(function(element,index){
  115.             if (element.numer == i) {
  116.               this.listaTowarow.push(element);
  117.             }
  118.           })
  119.         }
  120.       }
  121.     }*/
  122.   }
  123.  
  124. }
  125.  
  126. export class Towar {
  127.   constructor(public numer: number, public nazwa: string, public owner: Czlowiek, public fakturky: Array<Faktura>) {}
  128. }
  129.  
  130. export class Faktura {
  131.   constructor(public numer: number, public nazwa: string, public towary: Array<Towar>) {}
  132. }
  133.  
  134. export class Czlowiek {
  135.   constructor(public imie: string, public nazwisko: string) {}
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement