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