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