import { DBProvider } from 'ionic-np-dbprovider/src' import { ProductTaxEntity } from 'ionic-np-core-entitycomponent/src' import { ServiceProvider } from 'ionic-np-serviceprovider/src' import { Injectable } from '@angular/core' @Injectable() export class ProductTaxBC { constructor(private serviceprovider: ServiceProvider) { } public Read( where?: string): Promise { return new Promise(function (resolve, reject) { let dbProvider: DBProvider; let productTaxEntity: ProductTaxEntity[]; dbProvider = new DBProvider(); let retValue: Array; let strSql = ProductTaxEntity.TABLE_NAME; if (where) { strSql = strSql + " " + where }; dbProvider.Read(strSql). then((resultSet) => { if (resultSet.rows.length > 0) { productTaxEntity = new Array(resultSet.rows.length); for (let i = 0; i < resultSet.rows.length; i++) { productTaxEntity[i] = new ProductTaxEntity(); productTaxEntity[i].PRD_CD = resultSet.rows.item(i).PRD_CD; productTaxEntity[i].TAX_CD = resultSet.rows.item(i).TAX_CD; productTaxEntity[i].TAX_RATE = resultSet.rows.item(i).TAX_RATE; } } resolve(productTaxEntity); }); }); } public Create(productTaxEntity: Array): Promise { return new Promise(function (resolve, reject) { let dbProvider: DBProvider; dbProvider = new DBProvider(); let strSqls: Array; strSqls = new Array(); for (let i = 0; i < productTaxEntity.length; i++) { strSqls.push("insert into " + ProductTaxEntity.TABLE_NAME + " (PRD_CD,TAX_CD,TAX_RATE) VALUES ('" + productTaxEntity[i].PRD_CD + "','" + productTaxEntity[i].TAX_CD + "','" + productTaxEntity[i].TAX_RATE + "')" ); } dbProvider.ExecuteSql(strSqls) .then(() => { resolve(); }) .catch((e) => { reject(e); }); }); } public Get(httpUrl): Promise { return new Promise(resolve => { this.serviceprovider.Get(httpUrl).subscribe((result) => { let producttaxentity: Array; producttaxentity = new Array(); for (let i = 0; i < result.length; i++) { let producttax: ProductTaxEntity; producttax = new ProductTaxEntity(); producttax.PRD_CD = result[i].PRD_CD; producttax.TAX_CD = result[i].TAX_CD; producttax.TAX_RATE = result[i].TAX_RATE; producttaxentity.push(producttax); } resolve(producttaxentity); }); }); } }