User:Fareed9/sandbox

using namespace std; class CPlanModel { public: int dbConnect; void dbError; vector dbSelectAll(Tariff,char[]); vector dbSelect(Tariff,int); int dbAllocatePlan(Plan); int dbDeallocatePlan(char[]); int dbChangePlan(Plan); int dbvalidateCustId(int); int dbvalidateTariff(int,int); int dbgetCustId(char[]); int dbChangeService(Plan); int dbCheckService(int,char[]); int validatePhoneNo(char[]); };
 * 1) ifndef _DB_H
 * 2) define _DB_H
 * 3) include
 * 4) include
 * 5) include "../plan/plan.h"
 * 6) include "../../Tariff_Management/tariff/tariff.h"
 * 1) endif

using namespace std; EXEC SQL BEGIN DECLARE SECTION; char plancon[30]="c02consteam1@oracle"; //Change it as per db    	char planpwd[]="tcs"; int custId; int plantariffId; int service[20]; int planserviceId,serviceId1,serviceId2; char* phoneNo; char planlastUpdatedBy[30]; char planlastUpdatedDate[20]; char activeIndex; char ind; int speed_kb,rent_price,rate_per_mb,usage_limit_mb; char expdate[30]; int dayExp,monthExp,yearExp; int plantariffCount; int tariffCount1; sql_cursor plan_tariff_records; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA;
 * 1) include
 * 2) include
 * 3) include "../../Main/global.h"
 * 4) include "plan_db.h"
 * 1) define _NO_DATA_FOUND 1403
 * 2) define SUCCESS 0
 * 3) define FAILURE -1
 * 4) define SQLCA_STORAGE_CLASS

int CPlanModel::dbAllocatePlan(Plan p) { char e[20]; EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if (sqlca.sqlcode==0) {	}     	if(sqlca.sqlcode <0) {       	 return 0; }    	else { 		phoneNo=new char[12]; strcpy(phoneNo,p.generatePhoneNo); custId=p.getCustId; plantariffId=p.getTariffId; planserviceId=p.getServiceId; ind='Y'; EXEC SQL SELECT count(*) into :tariffCount1 from curr_plan_details where cust_id=:custId and serviceid=:planserviceId and tariffId=:plantariffId; EXEC SQL SELECT user,TO_CHAR(SYSDATE,'dd/mm/yyyy') into :planlastUpdatedBy,:planlastUpdatedDate FROM DUAL; if(tariffCount1==0) {		EXEC SQL insert into curr_plan_details(phone_no,active_ind,tariffid,serviceid,cust_id,lastupdatedby,lastupdateddatetm) values(:phoneNo,:ind,:plantariffId,:planserviceId,:custId,:planlastUpdatedBy,TO_DATE(:planlastUpdatedDate,'DD/MM/YYYY')); }		else {		return -5; }		if(sqlca.sqlcode <0) {           		cout<<" Error in Execute "<<sqlca.sqlcode<<" "<<sqlca.sqlerrm.sqlerrmc<<endl; return -2; }         	EXEC SQL COMMIT WORK RELEASE; return 1; } }

int CPlanModel::dbgetCustId(char phoneNO[]) {	phoneNo=new char[strlen(phoneNO)+1]; strcpy(phoneNo,phoneNO); EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {               return 0; }	EXEC SQL SELECT CUST_ID INTO :custId from CURR_PLAN_DETAILS WHERE PHONE_NO=:phoneNo; EXEC SQL COMMIT WORK RELEASE; return custId; }

int CPlanModel::dbvalidateCustId(int custID) {	custId=custID; EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {               return 0; }       EXEC SQL SELECT CUST_ID INTO :custId FROM CUSTOMER WHERE CUST_ID=:custId; if(sqlca.sqlcode <0) {               return -1; }       if(sqlca.sqlcode == _NO_DATA_FOUND) {                return -2; }       EXEC SQL COMMIT WORK RELEASE; return 1; }

int CPlanModel::validatePhoneNo(char phoneNO[]) {	phoneNo=new char[strlen(phoneNO)+1]; strcpy(phoneNo, phoneNO); EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {        	return 0; }   	EXEC SQL SELECT PHONE_NO INTO :phoneNo FROM curr_plan_details WHERE PHONE_NO=:phoneNo; if(sqlca.sqlcode <0) {       	return -1; }   	if(sqlca.sqlcode == _NO_DATA_FOUND) {       	 return -2; }   	EXEC SQL COMMIT WORK RELEASE; return 1; }

int CPlanModel::dbvalidateTariff(int serviceID,int tariffID) {	planserviceId=serviceID; plantariffId=tariffID; EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {               return 0; }       EXEC SQL SELECT count(*) into :tariffCount1 from tariff where serviceid=:planserviceId and tariffid=:plantariffId;

if(sqlca.sqlcode <0) {		cout<<sqlca.sqlerrm.sqlerrmc; return -1; }       if(sqlca.sqlcode == _NO_DATA_FOUND) {                cout<<sqlca.sqlerrm.sqlerrmc; return -2; }	if(tariffCount1==0) {		return -5; }

EXEC SQL COMMIT WORK RELEASE; return 1; }

int CPlanModel::dbCheckService(int serviceId,char phoneNO[]) {	phoneNo=new char[strlen(phoneNO)+1]; strcpy(phoneNo,phoneNO); serviceId1=serviceId; EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {              return 0; }       else EXEC SQL SELECT SERVICEID into :serviceId2 from curr_plan_details where PHONE_NO=:phoneNo and ACTIVE_IND='Y'; if(serviceId1!=serviceId2) {		return -5; } }

int CPlanModel::dbDeallocatePlan(char phoneNO[]) {	phoneNo=new char[strlen(phoneNO)+1]; strcpy(phoneNo,phoneNO); EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {        	return 0; }	EXEC SQL SELECT ACTIVE_IND into :activeIndex FROM CURR_PLAN_DETAILS WHERE PHONE_NO=:phoneNo; if(activeIndex==89 || activeIndex==121) {   	EXEC SQL update curr_plan_details set active_ind='N' where phone_no=:phoneNo; }	else {		return -2; }	if(sqlca.sqlcode <0) {   		cout< CPlanModel::dbSelectAll(Tariff tr,char phoneNO[]) {   	vector tariffs; tariffs.clear; phoneNo=new char[strlen(phoneNO)+1]; strcpy(phoneNo,phoneNO); plantariffCount=0; //cout<<"\nphone no in select all"<<phoneNo; EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {        return tariffs; }  	else {		EXEC SQL SELECT count(*) into :plantariffCount from tariff t,curr_plan_details p where t.tariffid=p.tariffid and p.PHONE_NO=:phoneNo and t.ACTIVE_IND='Y' and p.ACTIVE_IND='Y'; EXEC SQL ALLOCATE :plan_tariff_records; EXEC ORACLE OPTION(select_error=no); EXEC SQL SELECT CURSOR (SELECT t.SERVICEID,t.TARIFFID,t.SPEED_KBPS,t.RENTAL_PRICE,t.RATE_PER_MB,TO_NUMBER(TO_CHAR(t.EXPIRATION_DATE,'DD')),TO_NUMBER(TO_CHAR(t.EXPIRATION_DATE,'MM')),TO_NUMBER(TO_CHAR(t.EXPIRATION_DATE,'YYYY')),t.USAGE_LIMIT_MB from tariff t,curr_plan_details p where t.tariffid=p.tariffid and p.PHONE_NO=:phoneNo and t.ACTIVE_IND='Y' and p.ACTIVE_IND='Y') INTO :plan_tariff_records FROM DUAL; EXEC ORACLE OPTION(select_error=yes); if(sqlca.sqlcode <0) {                       cout<<" Error in DB QUERY "<<sqlca.sqlcode<<" "<<sqlca.sqlerrm.sqlerrmc<<endl; }               if(sqlca.sqlcode == _NO_DATA_FOUND) {                       EXEC SQL CLOSE :plan_tariff_records; EXEC SQL COMMIT WORK RELEASE; return tariffs; }               else {			//cout<<"count"<<plantariffCount; if(plantariffCount==1) {                       EXEC SQL FETCH :plan_tariff_records into :planserviceId,:plantariffId,:speed_kb,:rent_price,:rate_per_mb,:dayExp,:monthExp,:yearExp,:usage_limit_mb; tr.setServiceId(planserviceId); tr.setTariffId(plantariffId); tr.setRental(rent_price); tr.setRate_Per_MB(rate_per_mb); Date d1(dayExp,monthExp,yearExp); tr.setExpirationDate(d1); tr.setUsage_Limit_MB(usage_limit_mb);

tariffs.push_back(tr); }			else {				cout<<"Plan does not exist for this phone number"< CPlanModel::dbSelect(Tariff t,int ServiceID) {   	phoneNo=new char[11]; vector tariffs; Date d1; int day; int serviceId1; planserviceId=ServiceID; EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if(sqlca.sqlcode <0) {       	return tariffs; }  	else {      EXEC SQL SELECT count(*) into :plantariffCount from tariff where SERVICEID=:planserviceId and ACTIVE_IND='Y'; EXEC SQL ALLOCATE :plan_tariff_records; EXEC ORACLE OPTION(select_error=no); EXEC SQL SELECT CURSOR (SELECT SERVICEID,TARIFFID,SPEED_KBPS,RENTAL_PRICE,RATE_PER_MB,TO_NUMBER(TO_CHAR(EXPIRATION_DATE,'DD')),TO_NUMBER(TO_CHAR(EXPIRATION_DATE,'MM')),TO_NUMBER(TO_CHAR(EXPIRATION_DATE,'YYYY')),USAGE_LIMIT_MB from tariff where SERVICEID=:planserviceId and ACTIVE_IND='Y') INTO :plan_tariff_records FROM DUAL; EXEC ORACLE OPTION(select_error=yes); if(sqlca.sqlcode <0) {        		//cout<<" Error in DB QUERY "<<sqlca.sqlcode<<" "<<sqlca.sqlerrm.sqlerrmc<<endl; }    		if(sqlca.sqlcode == _NO_DATA_FOUND) {        		EXEC SQL CLOSE :plan_tariff_records; EXEC SQL COMMIT WORK RELEASE; return tariffs; }    		else {	   		for(int i=0;i<plantariffCount;i++) { EXEC SQL FETCH :plan_tariff_records into :planserviceId,:plantariffId,:speed_kb,:rent_price,:rate_per_mb,:dayExp,:monthExp,:yearExp,:usage_limit_mb; // :dayExp,:monthExp,:yearExp if(sqlca.sqlcode<0) {           		//	cout<<" Error in DB QUERY "<<sqlca.sqlcode<<" "<<sqlca.sqlerrm.sqlerrmc<<endl; }		 		t.setServiceId(planserviceId); t.setTariffId(plantariffId); t.setSpeed_Kbps(speed_kb); t.setRental(rent_price); t.setRate_Per_MB(rate_per_mb); Date d1(dayExp,monthExp,yearExp); t.setExpirationDate(d1); t.setUsage_Limit_MB(usage_limit_mb); tariffs.push_back(t); }		}		EXEC SQL CLOSE :plan_tariff_records; EXEC SQL COMMIT WORK RELEASE; return tariffs; } }

int CPlanModel::dbChangePlan(Plan p) { EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if (sqlca.sqlcode==0) {       	}      		 if(sqlca.sqlcode <0) {                return 0; }       	else {               phoneNo=new char[11]; strcpy(phoneNo,p.getPhoneNo); plantariffId=p.getTariffId; EXEC SQL SELECT user,TO_CHAR(SYSDATE,'dd/mm/yyyy') into :planlastUpdatedBy,:planlastUpdatedDate FROM DUAL; EXEC SQL UPDATE CURR_PLAN_DETAILS SET TARIFFID=:plantariffId,LASTUPDATEDBY=:planlastUpdatedBy,LASTUPDATEDDATETM=TO_DATE(:planlastUpdatedDate,'DD/MM/YYYY') WHERE PHONE_NO=:phoneNo; //,:lastUpdatedBy,TO_DATE(:planlastUpdatedDate,'DD/MM/YYYY'));

if(sqlca.sqlcode <0) {                       cout<<" Error in Execute "<<sqlca.sqlcode<<" "<<sqlca.sqlerrm.sqlerrmc<<endl; return -2; }               EXEC SQL COMMIT WORK RELEASE; return 1; } }

int CPlanModel::dbChangeService(Plan p) { EXEC SQL CONNECT :plancon IDENTIFIED BY :planpwd ; if (sqlca.sqlcode==0) {       }        if(sqlca.sqlcode <0) {                return 0; }       else {               phoneNo=new char[11]; strcpy(phoneNo,p.getPhoneNo); plantariffId=p.getTariffId; planserviceId=p.getServiceId; custId=p.getCustId; EXEC SQL INSERT INTO CURR_PLAN_DETAILS(phone_no,active_ind,tariffid,serviceid,cust_id) values(:phoneNo,'Y',:plantariffId,:planserviceId,:custId);;

//,:lastUpdatedBy,TO_DATE(:planlastUpdatedDate,'DD/MM/YYYY'));

if(sqlca.sqlcode <0) {                       cout<<" Error in Execute "<<sqlca.sqlcode<<" "<<sqlca.sqlerrm.sqlerrmc<<endl; return -2; }               EXEC SQL COMMIT WORK RELEASE; return 1; } } void CPlanModel::dbError { cout<<" Error in DB QUERY "<<sqlca.sqlcode<<" "<<sqlca.sqlerrm.sqlerrmc<<endl; }

//#include "../emp/employee.h" using namespace std; class Plan {	char* phoneNo; int tariffId; int custId; int serviceId; char* lastUpdatedBy; Date lastUpdatedDate; char* activeIndex; public: Plan; Plan(char[],int,int,int,char[],Date,char[]); Plan(const Plan&); void setPhoneNo(char[]); char* generatePhoneNo; char* getPhoneNo; int getTariffId; void setTariffId(int); int getCustId; void setCustId(int); int getServiceId; void setServiceId(int); void setLastUpdatedBy(char[]); char* getLastUpdatedBy; void setLastUpdatedDate(Date); Date getLastUpdatedDate; void setActiveIndex(char[]); char convert(int); char* getActiveIndex; ~Plan; };
 * 1) ifndef _PLAN_H
 * 2) define _PLAN__H
 * 3) include
 * 4) include
 * 1) include
 * 2) include"Date.h"


 * 1) endif


 * 1) include"plan.h"

Plan::Plan {	phoneNo=new char[1]; strcpy(phoneNo,"\0"); tariffId=0; serviceId=0; custId=0; lastUpdatedBy=new char[1]; strcpy(lastUpdatedBy,"\0");

activeIndex=new char[1]; strcpy(activeIndex,"\0"); } Plan::Plan(char phoneNo[],int tariffId,int serviceId,int custId,char lastUpdatedBy[],Date lastUpdatedDate,char activeIndex[]) {	int len=strlen(phoneNo); this->phoneNo=new char[len+1]; strcpy(this->phoneNo,phoneNo); this->tariffId=tariffId; this->serviceId=serviceId; this->custId=custId; len=strlen(lastUpdatedBy); this->lastUpdatedBy=new char[len+1]; strcpy(this->lastUpdatedBy,lastUpdatedBy);

this->lastUpdatedDate=lastUpdatedDate;

len=strlen(activeIndex); this->activeIndex=new char[len+1]; strcpy(this->activeIndex,activeIndex); } Plan::Plan(const Plan &ref) {

tariffId=ref.tariffId; serviceId=ref.serviceId; custId=ref.custId; int len=strlen(ref.phoneNo); phoneNo=new char[len+1]; strcpy(phoneNo,ref.phoneNo); lastUpdatedDate=ref.lastUpdatedDate;

len=strlen(ref.activeIndex); activeIndex=new char[len+1]; strcpy(activeIndex,ref.activeIndex);

len=strlen(ref.lastUpdatedBy); lastUpdatedBy=new char[len+1]; strcpy(lastUpdatedBy,ref.lastUpdatedBy); }

void Plan::setTariffId(int tariffId) {	this->tariffId=tariffId; }

int Plan::getTariffId {	return tariffId; }

int Plan::getServiceId {	return serviceId; }

void Plan::setServiceId(int ServiceId) {	this->serviceId=ServiceId; }

void Plan::setCustId(int custId) {	this->custId=custId; }

int Plan::getCustId {	return custId; } void Plan::setPhoneNo(char PhoneNo[]) {	int len=strlen(PhoneNo); this->phoneNo=new char[len+1]; strcpy(this->phoneNo,PhoneNo);

}

char* Plan::getPhoneNo {	return phoneNo; }

char* Plan::generatePhoneNo {	phoneNo=new char[11]; char* ph1; char* ph2; ph1=new char[11]; ph2=new char[11]; srand(time(NULL)); int x=9999+(rand*rand)%10000; int y=9999+(rand*rand)%100000; ph1[0]='9'; for(int c1=1;c1<5;c1++) { 		ph1[c1]=convert(x%10); x=x/10; }	for(int c=0;c<5;c++) {		ph2[c]=convert(y%10); y=y/10; }	if(strlen(ph1)!=5 || strlen(ph2)!=5) {		generatePhoneNo; }	else phoneNo=strcat(ph1,ph2); return phoneNo; }

char Plan::convert(int a) { switch(a) {       case 0: return '0'; break; case 1: return '1'; break; case 2: return '2'; break; case 3: return '3'; break; case 4: return '4'; break; case 5: return '5'; break; case 6: return '6'; break; case 7: return '7'; break; case 8: return '8'; break; case 9: return '9'; break; default: break; } }

void Plan::setLastUpdatedBy(char lastUpdatedBy[]) {	int len=strlen(lastUpdatedBy); this->lastUpdatedBy=new char[len+1]; strcpy(this->lastUpdatedBy,lastUpdatedBy); } char* Plan::getLastUpdatedBy {	return lastUpdatedBy; } void Plan::setLastUpdatedDate(Date lastUpdatedDate) {	this->lastUpdatedDate=lastUpdatedDate; } Date Plan::getLastUpdatedDate {	return lastUpdatedDate; } void Plan::setActiveIndex(char activeIndex[]) {	int len=strlen(activeIndex); this->activeIndex=new char[len+1]; strcpy(this->activeIndex,activeIndex); } char* Plan::getActiveIndex {	return activeIndex; } Plan::~Plan {	delete[] phoneNo; delete[] lastUpdatedBy; delete[] activeIndex; }

using namespace std; class Date {	int day; int month; int year; public: int getDay; int getMonth; int getYear; void setDay(int); void setMonth(int); void setYear(int); Date; Date(int,int,int); Date (const Date &ref); char get_char(int); char* get_date(char*); };
 * 1) ifndef _Date_H
 * 2) define _Date_H
 * 3) include
 * 1) endif

int Date:: getDay {			return day; }		int Date:: getMonth {			return month; }		int Date:: getYear {			return year; }		void Date:: setDay(int day) {			this->day=day; }		void Date:: setMonth(int month) {			this->month=month; }		void Date:: setYear(int year) {			this->year=year; }		Date:: Date {			day=0; month=0; year=0; }		Date::Date(const Date &ref) {			this->day=ref.day; this->month=ref.month; this->year=ref.year; }		Date:: Date(int day, int month, int year) {			this->day=day; this->month=month; this->year=year; }
 * 1) include"Date.h"

char Date::get_char(int x)		{ switch(x) {       case 0: return '0'; break; case 1: return '1'; break; case 2: return '2'; break; case 3: return '3'; break; case 4: return '4'; break; case 5: return '5'; break; case 6: return '6'; break; case 7: return '7'; break; case 8: return '8'; break; case 9: return '9'; break; default: break; } }

char* Date::get_date(char *d) {	int a=day,b=month,c=year; d[0]=get_char(a/10); d[1]=get_char(a%10); d[2]='/'; d[3]=get_char(b/10); d[4]=get_char(b%10); d[5]='/'; d[9]=get_char(c%10); c=c/10; d[8]=get_char(c%10); c=c/10; d[7]=get_char(c%10); c=c/10; d[6]=get_char(c%10); d[10]='\0'; return d; }

using namespace std;
 * 1) ifndef PLAN_MAIN_H
 * 2) define PLAN_MAIN_H
 * 3) include "../Plan_Controller/plan_controller.h"
 * 4) include "../PlanUI/planui.h"
 * 5) include
 * 6) include
 * 7) include "../Plan_db/plan_db.h"
 * 8) define SUCCESS 0
 * 9) define FAILURE -1

class CPlan_main {  public: int initiate_plan; };


 * 1) endif


 * 1) include "plan_main.h"

int CPlan_main::initiate_plan {	CPlanController cl; CPLANUI ui; CPlanModel model; //	try //	{ 	int choice=0; ui.displayMenu; choice=ui.getOption; while (choice!=5) {      		switch(choice) {         		case 1: cl.allocatePlan(model,ui); break; case 2: cl.viewPlan(model,ui); break; case 3: cl.changePlan(model,ui); break; case 4: cl.deallocatePlan(model,ui); break; case 5: exit(0); default: ui.displayString("You have given a invalid option "); }      		ui.displayMenu; choice=ui.getOption; } } //	catch(...){cout<<"\nUNKNOWN EXCEPTION";}

using namespace std; class CPLANUI {	int custId; int tariffId; int serviceId; char phoneNo[11]; char lastUpdatedBy[20]; char lastUpdatedDate[20]; char activeIndex[3]; public: void displayMenu; void displayServiceMenu; int getOption; int getServiceId; int getServiceOption; int getCustomerId; int getTariffId; char* getPhoneNo; char* getActiveIndex; void displayString(char*); // void display(Plan); void display(vector); void displayError; //char convert(int); // void setPlan(int,int,int,char*,char*); int countDigit(int); };
 * 1) ifndef _PLANUI_H
 * 2) define _PLANUI_H
 * 3) define SUCCESS 0
 * 4) define FAILURE -1
 * 5) include
 * 6) include
 * 7) include
 * 8) include
 * 9) include
 * 10) include "../../Tariff_Management/tariff/tariff.h"
 * 1) endif

void CPLANUI::displayMenu {  cout<<"\t\t\t\t\t\tPLAN MANAGEMENT"<<endl<<endl; cout<<"\t\t\t\t=============================================="<<endl<<endl; // cout<<"          1. Display All Plan Details"<<endl<<endl; cout<<"\t\t\t\t1. Allocate Plan"<<endl<<endl; cout<<"\t\t\t\t2. View Plan Details"<<endl<<endl; cout<<"\t\t\t\t3. Change Plan"<<endl<<endl; cout<<"\t\t\t\t4. Deallocate Plan"<<endl<<endl; cout<<"\t\t\t\t5. Main Menu"<>opt; if(opt<1 && opt>5) {	cout<<"Invalid output.Please try Again"; getServiceOption; }	return opt; } int CPLANUI::getOption {   int opt; cout<<"Enter your option\t\t:"; while(!(cin>>opt)) {	cout<<"Invalid output.Please try Again"; for(int i=0; i<2; i++) cout<<"\b\r"; cout<<"\t\t\t\t:"; //cout<<"\b\r"; cin.clear; cin.ignore(numeric_limits ::max,'\n'); }      cout<<"\n"; return opt; }

int CPLANUI:: countDigit(int n) { int ct=0; while(n!=0) {    ct++; n=n/10; }   return ct; } int CPLANUI::getCustomerId {	//cout<<"\b\r"; //cout<<"\n"; //cout<<"\t\t\t\t\t:"; cout<<"Enter Customer Id\t\t:"; while(!(cin>>custId)) {       cout<<"Invalid output.Please try again: "; for(int i=0; i<2; i++) cout<<"\b\r"; cout<<"\t\t\t\t:"; cin.clear; cin.ignore(numeric_limits ::max,'\n'); }   cout<<"\n"; return custId; }

int CPLANUI::getTariffId {   //getchar; cout<<" Enter Tariff Id\t\t: "; while(!(cin>>tariffId)) {       cout<<"Invalid output.Please try again: "; for(int i=0; i<2; i++) cout<<"\b\r"; cout<<"\t\t\t\t:";

cin.clear; cin.ignore(numeric_limits ::max,'\n'); }  cout<<"\n"; return tariffId; }

int CPLANUI::getServiceId {     //	getchar; cout<<"Enter service Id\t\t: "; while(!(cin>>serviceId)) {       cout<<"Invalid output.Please try again: "; for(int i=0; i<2; i++) cout<<"\b\r"; cout<<"\t\t\t\t:";

cin.clear; cin.ignore(numeric_limits ::max,'\n'); }	 if(serviceId<1 || serviceId>5) {	cout<<"Invalid output.Please try again: "; for(int i=0; i<2; i++) cout<<"\b\r"; cout<<"\t\t\t:";

//cin.clear; //cin.ignore(numeric_limits ::max,'\n'); getServiceId; }		cout<<"\n"; return serviceId; }

char* CPLANUI::getPhoneNo {      	getchar; cout<<"Enter Phone No\t\t\t: "; //cin>>phoneNo;

cin.clear; cin.getline(phoneNo,11); if(strlen(phoneNo)!=10) {		cout<<"\nEnter 10 digits"; /* for(int i=0; i<2; i++) cout<<"\b\r"; cout<<"\t\t\t\t:"; */		getPhoneNo; }	else {		for(int i=0;i<10;i++) {			int y=phoneNo[i]; if(y<48 || y>57) {					/*cout<<"\n"; for(int i=0; i<2; i++) cout<<"\b\r"; cout<<"\t\t\t\t:";*/

getPhoneNo; }		}	}	return phoneNo; }

void CPLANUI::displayString(char* str) {    cout< tariff_records) {  system("clear"); vector::iterator itr_tariff; cout<<"\t\t\t..........................Tariff Details ................"<<endl<<endl; cout<<"\tServiceId"<<"\tTariffId"<<"\tSpeed(kbps)"<<" Rental_Price "<<"Rate/MB"<<"   Expiration Date    "<<" Usage Limit"<<endl; cout<<"\t"<<"\t--- "<<" "<<"--- "<<"-- "<<"- "<<"-"<<endl; for (itr_tariff = tariff_records.begin; itr_tariff != tariff_records.end; itr_tariff++) { cout<<"\n"; cout<<"\t"<<(*itr_tariff).getServiceId<<"\t\t"<<(*itr_tariff).getTariffId<<"\t\t"<<(*itr_tariff).getSpeed_Kbps<<"\t\t"<<(*itr_tariff).getRental<<"\t  "<<(*itr_tariff).getRate_Per_MB<<"\t\t"<<(*itr_tariff).getExpirationDate.getDay<<"/"<<(*itr_tariff).getExpirationDate.getMonth<<"/"<<(*itr_tariff).getExpirationDate.getYear<<"\t"<<(*itr_tariff).getUsage_Limit_MB<<endl; cout<<"\t_____________________________________________________________________________________________________"<<endl; //cout<<"\n"; //cout<<"\n";

} } void CPLANUI:: displayError{cout<<"Error takes place"<<endl;}

using namespace std; class CPlanController { public: void allocatePlan(CPlanModel&,CPLANUI&); void viewPlan(CPlanModel&,CPLANUI&); void changePlan(CPlanModel&,CPLANUI&); void deallocatePlan(CPlanModel&,CPLANUI&); };
 * 1) ifndef _PLAN_CONTROLLER_H
 * 2) define _PLAN_CONTROLLER_H
 * 3) include
 * 4) include
 * 5) include
 * 6) include "../../Tariff_Management/tariff/tariff.h"
 * 7) include "../Plan_db/plan_db.h"
 * 8) include "../PlanUI/planui.h"
 * 1) define SUCCESS 0
 * 2) define FAILURE -1
 * 1) endif

/////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name :  // Summary :  // Input Parameters :  // Output Parameters : <List of Output Parameters with respective Data type> // Return Value : <Return Value> // ///////////////////////////////////////////////////////////////////////////////////////////////
 * 1) include "plan_controller.h"
 * 2) include<string.h>

void CPlanController::viewPlan(CPlanModel &m,CPLANUI &ui) {	int result = 0; vector<Tariff> tariff_records; Tariff t;  	char* phoneNo; phoneNo=new char[12]; strcpy(phoneNo,ui.getPhoneNo); ui.displayString(phoneNo); if(m.validatePhoneNo(phoneNo)==1) { 		tariff_records=m.dbSelectAll(t,phoneNo); if(tariff_records.size!=0) {			ui.display(tariff_records); } 		else if(result==-3) ui.displayString("Records could not be Fetched........"); else if(result==0) ui.displayString("Phone no not in use..........."); else if(result==-1) ui.displayString("Could not open cursur ........."); else {			ui.displayString("Record not Found........"); }	}	else {		ui.displayString("Phone Number not Found........"); } }

/////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : <Name of the Function> // Summary : <Description in short> // Input Parameters : <List of Input Parameters with respective Data type> // Output Parameters : <List of Output Parameters with respective Data type> // Return Value : <Return Value> // /////////////////////////////////////////////////////////////////////////////////////////////// void CPlanController::allocatePlan(CPlanModel &m,CPLANUI &ui) {      	int custId; int serviceId; int tariffId; char* phoneNo; char* lastUpdatedBy; char* activeIndex; int result=0; Plan p;       Tariff t;      	vector<Tariff> tariff_records; custId=ui.getCustomerId; if(m.dbvalidateCustId(custId)!=1) {		ui.displayString("Customer Id not found."); allocatePlan(m,ui); }	ui.displayServiceMenu; serviceId=ui.getServiceId; tariff_records=m.dbSelect(t,serviceId); if(tariff_records.size!=0) {		ui.display(tariff_records);} else if(result==-3) ui.displayString("Records could not be Fetched."); else if(result==0) exit(1); else if(result==-1) ui.displayString("Could not open cursor."); else ui.displayString("Record not Found."); tariffId=ui.getTariffId; if(m.dbvalidateTariff(serviceId,tariffId)==-5) {		ui.displayString("Tariff id not Found."); allocatePlan(m,ui); }      if( m.dbvalidateTariff(serviceId,tariffId)==-1) ui.displayString("Error........."); if( m.dbvalidateTariff(serviceId,tariffId)==-2) ui.displayString("Record not retrieved successfully.........."); phoneNo=new char[12]; strcpy(phoneNo,p.generatePhoneNo); p.setCustId(custId); p.setTariffId(tariffId); p.setServiceId(serviceId); p.setPhoneNo(phoneNo); if(m.validatePhoneNo(phoneNo)==1) ui.displayString("Duplicate Phone Number. Record cannot be inserted........."); if( m.dbAllocatePlan(p)==1) { 		ui.displayString("Record added successfully...........\n"); ui.displayString("Phone Number"); ui.displayString(""); ui.displayString(phoneNo); }	else if( m.dbAllocatePlan(p)==0) ui.displayString("Connection error..............."); else if( m.dbAllocatePlan(p)==-1) ui.displayString("Phone Number exists........."); else if( m.dbAllocatePlan(p)==-2) ui.displayString("Record not added successfully."); else if(m.dbAllocatePlan(p)==-5) ui.displayString("Plan is already taken."); } /////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : <Name of the Function> // Summary : <Description in short> // Input Parameters : <List of Input Parameters with respective Data type> // Output Parameters : <List of Output Parameters with respective Data type> // Return Value : <Return Value> // /////////////////////////////////////////////////////////////////////////////////////////////// void CPlanController::changePlan(CPlanModel &m,CPLANUI &ui) {      int custId; int serviceId; int tariffId; int checkId; char* phoneNo; char* lastUpdatedBy; char* activeIndex; int result=0; Plan p;       Tariff t;        vector<Tariff> tariff_records; phoneNo=new char[12]; strcpy(phoneNo,ui.getPhoneNo); if(m.validatePhoneNo(phoneNo)==1) {		custId=m.dbgetCustId(phoneNo); ui.displayServiceMenu; serviceId=ui.getServiceId; checkId=m.dbCheckService(serviceId,phoneNo); tariff_records=m.dbSelect(t,serviceId); if(tariff_records.size!=0) {			ui.display(tariff_records); }      		else if(result==-3) ui.displayString("Records could not be Fetched........"); else if(result==0) changePlan(m,ui); //ui.displayString("Error in connection........"); else if(result==-1) ui.displayString("Could not open cursur ........."); else ui.displayString("Record not Found........"); tariffId=ui.getTariffId; if(checkId==-5) {			m.dbDeallocatePlan(phoneNo); phoneNo=new char[20]; strcpy(phoneNo,p.generatePhoneNo); p.setPhoneNo(phoneNo); //cout<<"ph:"<<phoneNo; p.setTariffId(tariffId); p.setServiceId(serviceId); p.setCustId(custId);

if(m.dbChangeService(p)==1) ui.displayString("Record updated successfully.........."); else if(m.dbChangeService(p)==0) ui.displayString("Connection error        "); else if(m.dbChangeService(p)==-1) ui.displayString("Plan number exists........."); else if(m.dbChangeService(p)==-2) ui.displayString("Record not added successfully.........."); }     			else {			p.setPhoneNo(phoneNo); p.setTariffId(tariffId); if(m.dbChangePlan(p)==1) ui.displayString("Record updated successfully.........."); else if(m.dbChangePlan(p)==0) ui.displayString("Connection error        "); else if(m.dbChangePlan(p)==-1) ui.displayString("Plan number exists........."); else if(m.dbChangePlan(p)==-2) ui.displayString("Record not added successfully.........."); }		} 	else {		ui.displayString("Given Phone Number Does not exists......."); } }

/////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : <Name of the Function> // Summary : <Description in short> // Input Parameters : <List of Input Parameters with respective Data type> // Output Parameters : <List of Output Parameters with respective Data type> // Return Value : <Return Value> // ///////////////////////////////////////////////////////////////////////////////////////////////  void CPlanController::deallocatePlan(CPlanModel &m,CPLANUI &ui) {	char* phoneNo=new char[12]; strcpy(phoneNo,ui.getPhoneNo); if (m.dbDeallocatePlan(phoneNo)==1) ui.displayString("Record deleted successfully............."); else if (m.dbDeallocatePlan(phoneNo)==0) ui.displayString("Connection error        "); else if (m.dbDeallocatePlan(phoneNo)==-2) ui.displayString("Record not found.................        ");

}