Skip to content

Instantly share code, notes, and snippets.

@tps2015gh
Last active October 4, 2018 17:07
Show Gist options
  • Save tps2015gh/99c2990c5cb7a2663ef54057d563b923 to your computer and use it in GitHub Desktop.
Save tps2015gh/99c2990c5cb7a2663ef54057d563b923 to your computer and use it in GitHub Desktop.
มาตรา 11 และ มาตรา 12 ร่าง พรบ ความมั่นคงไซเบอร์แห่งชาติ
// class Person{
// constructor(param){
// this.idcard = param.idcard
// this.fullname = param.fullname
// }
// }
// @ts-check
class Person{
idcard :string
fullname :string
constructor(idcard :string , fullname : string ){
this.idcard = idcard
this.fullname = fullname
}
}
class PersonPayPair{
p : Person ;
amount : number ;
constructor(p : Person, amount : number){
this.p = p
this.amount = amount
}
}
class PayTable {
ar_PersonPayPair : Array<PersonPayPair> = [ ]
constructor(){
this.ar_PersonPayPair = []
}
add( p :Person , amount : number){
let p1 = new PersonPayPair(p, amount )
this.ar_PersonPayPair.push (p1 )
}
}
class AnuKumMaKarnGroup{
title : string
private ar_person : Array<Person> = []
paytable : PayTable
constructor( title : string ){
this.title = title
this.ar_person = [ ]
this.paytable = new PayTable()
}
AddMember( p : Person){
this.ar_person.push( p )
console.log( "Add Memeber ")
//console.log( p )
//console.log( this.ar_person )
}
getList_Person(){
console.log("Group getList_Person()")
//console.log( this.ar_person)
return this.ar_person
}
addPay(p : Person, amount : number){
this.paytable.add(p,amount)
}
}
class KPC{
ar_AnuGroup : Array<AnuKumMaKarnGroup> = []
addAnuGroup( anuGr1 : AnuKumMaKarnGroup ){
this.ar_AnuGroup.push( anuGr1 )
}
authosize_AnuKumMaKarn( anuGroup : AnuKumMaKarnGroup , p : Person ){
anuGroup.AddMember(p)
}
getList_AnuKumMaKarnGroup() : Array<AnuKumMaKarnGroup> {
return this.ar_AnuGroup
}
getList_Person() : Person[] {
let ar : Array<Person> = []
this.ar_AnuGroup.forEach( anuGroup => {
let ar_per = anuGroup.getList_Person()
//console.log( ar_per )
ar_per.forEach(per=> {
//console.log(per)
ar.push(per)
})
})
return ar
}
setPersonPay( anuGroup : AnuKumMaKarnGroup , p :Person , amount : number){
anuGroup.addPay(p , amount )
}
}
//===============================================================
// test case
var kpc = new KPC()
var p1 = new Person('100000',"TestUser1")
var p2 = new Person('100001',"TestUser2")
var anuGroup1 = new AnuKumMaKarnGroup("AnuGroup1")
anuGroup1.addPay(p1,20000)
anuGroup1.addPay(p2,30000)
kpc.addAnuGroup(anuGroup1 )
kpc.authosize_AnuKumMaKarn( anuGroup1 , p1 )
kpc.authosize_AnuKumMaKarn( anuGroup1 , p2 )
//kpc.authosize_AnuKumMaKarn(anuGroup1 ,p1)
console.log( p1 )
console.log( kpc )
console.log("==== List of Group ====")
console.log( kpc.getList_AnuKumMaKarnGroup() )
console.log("==== List of Person ====")
console.log( kpc.getList_Person() )
console.log("==== List Paytable ====")
console.log(anuGroup1.paytable)
start tsc *.ts --watch
$ node m11_12.js
Add Memeber
Add Memeber
Person { idcard: '100000', fullname: 'TestUser1' }
KPC {
ar_AnuGroup:
[ AnuKumMaKarnGroup { ar_person: [Array], title: 'AnuGroup1', paytable: [PayT
able] } ] }
==== List of Group ====
[ AnuKumMaKarnGroup {
ar_person: [ [Person], [Person] ],
title: 'AnuGroup1',
paytable: PayTable { ar_PersonPayPair: [Array] } } ]
==== List of Person ====
Group getList_Person()
[ Person { idcard: '100000', fullname: 'TestUser1' },
Person { idcard: '100001', fullname: 'TestUser2' } ]
==== List Paytable ====
PayTable {
ar_PersonPayPair:
[ PersonPayPair { p: [Person], amount: 20000 },
PersonPayPair { p: [Person], amount: 30000 } ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment