⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posbackoracle.pc

📁 一个不错的POS系统
💻 PC
字号:
#include "posBackOracle.h"
#include "pub.h"
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>




int addproduct(struct barinformation * barInfo)
{
	char bar_code[10];
	char product_name[32];
	char unit[18];
	char spec[18];	
	char tmp[40]={0};
	float sale_price=0.0f;	
	float purchase_price=0.0f;		
	float discount=0.0f; 
	int num=0;
	memset(bar_code,0,sizeof(bar_code));
	memset(product_name,0,sizeof(product_name));
	memset(unit,0,sizeof(unit));
	memset(spec,0,sizeof(spec));
	makelog("debug.log","add product found!>>>>>>>");
	strcpy(bar_code,barInfo->bar_code);
	strcpy(product_name,barInfo->product_name);
	strcpy(unit,barInfo->unit);
	strcpy(spec,barInfo->spec);
	sale_price=barInfo->sale_price;
	purchase_price=barInfo->purchase_price;
	discount=barInfo->discount;
	num=barInfo->num;

	EXEC SQL WHENEVER NOT FOUND GOTO not_found;
	EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
	EXEC SQL INSERT INTO product(bar_code,product_name,unit,spec,sale_price,purchase_price,num,discount) VALUES(:bar_code,:product_name,:unit,:spec,:sale_price,:purchase_price,:num,:discount);
	makelog("debug.log","add product found!!!!!!!!");
	EXEC SQL COMMIT;
	return 0;

 not_found:
	makelog("debug.log","add product found");
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL ROLLBACK;
    return -1;
 sqlerr:
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
	EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL ROLLBACK;
	return -2;
}

int IsInDB(char * barcode)
{
	
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;
	EXEC SQL SELECT num FROM PRODUCT WHERE bar_code=:barcode;
	makelog("debug.log","barcode is in");
	return 0;
  not_found:
	makelog("debug.log","barcode not  found");
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	return -1;
  sqlerr:
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
	
	return -2;
}
int DelProduct(char * barcode)
{
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;
	EXEC SQL DELETE FROM PRODUCT WHERE bar_code=:barcode;
	EXEC SQL COMMIT;
	return 0;

  not_found:
	makelog("debug.log","delbar not  found");
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL ROLLBACK;
	return -1;
  sqlerr:
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL ROLLBACK;
	return -2;
}
int QueryBarInfo(struct barinformation * barInfo,char * barcode)
{
	char bar_code[10];
	char product_name[32];
	char unit[18];
	char spec[18];	
	char tmp[40]={0};
	float sale_price=0.0f;	
	float purchase_price=0.0f;		
	float discount=0.0f; 
	int num=0;
	short sproduct_name;
	short sunit;
	short sspec;
	memset(bar_code,0,sizeof(bar_code));
	memset(product_name,0,sizeof(product_name));
	memset(unit,0,sizeof(unit));
	memset(spec,0,sizeof(spec));
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;
	EXEC SQL SELECT * INTO :bar_code,:product_name :sproduct_name,:unit :sunit,:spec :sspec,:sale_price,:purchase_price,:num,:discount FROM PRODUCT WHERE bar_code=:barcode;
	
	Trim(bar_code);
	Trim(product_name);
	Trim(unit);
	Trim(spec);
	strcpy(barInfo->bar_code,bar_code);
	strcpy(barInfo->product_name,product_name);
	strcpy(barInfo->unit,unit);
	strcpy(barInfo->spec,spec);
	barInfo->sale_price=sale_price;
	barInfo->purchase_price=purchase_price;
	barInfo->discount=discount;
	barInfo->num=num;
	return 0;
  not_found:
	makelog("debug.log","delbar not  found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;	
	return -1;
  sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
	return -2;	
}
int updateBarInfo(struct barinformation * barInfo,char * barcode)
{
	char bar_code[10];
	char product_name[32];
	char unit[18];
	char spec[18];	
	char tmp[40]={0};
	float sale_price=0.0f;	
	float purchase_price=0.0f;		
	float discount=0.0f; 
	int num=0;
	Trim(barInfo->bar_code);
	Trim(barInfo->product_name);
	Trim(barInfo->unit);
	Trim(barInfo->spec);
	memset(bar_code,0,sizeof(bar_code));
	memset(product_name,0,sizeof(product_name));
	memset(unit,0,sizeof(unit));
	memset(spec,0,sizeof(spec));
	strcpy(bar_code,barInfo->bar_code);
	strcpy(product_name,barInfo->product_name);
	strcpy(unit,barInfo->unit);
	strcpy(spec,barInfo->spec);
	sale_price=barInfo->sale_price;
	purchase_price=barInfo->purchase_price;
	discount=barInfo->discount;
	num=barInfo->num;
	
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;
	EXEC SQL UPDATE PRODUCT SET bar_code=:bar_code,product_name=:product_name,unit=:unit,spec=:spec,sale_price=:sale_price,purchase_price=:purchase_price,num=:num,discount=:discount WHERE bar_code=:barcode;
	EXEC SQL COMMIT;
	return 0;
 not_found:
	makelog("debug.log","delbar not  found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL ROLLBACK;
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL ROLLBACK;
	return -2;	
	
}
int AddAccount(struct staffinfomation * staffInfo)
{
	char staff_id[8];
	char staff_name[16];
	char staff_pwd[18];
	char remark[32];
	memset(staff_id,0,sizeof(staff_id));
	memset(staff_name,0,sizeof(staff_name));
	memset(staff_pwd,0,sizeof(staff_pwd));
	memset(remark,0,sizeof(remark));
	int staff_type;
	strcpy(staff_id,staffInfo->staff_id);
	strcpy(staff_name,staffInfo->staff_name);
	strcpy(staff_pwd,staffInfo->staff_pwd);
	strcpy(remark,staffInfo->remark);
	staff_type=staffInfo->staff_type;
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;
	EXEC SQL INSERT INTO STAFF VALUES(:staff_id,:staff_name,:staff_pwd,:staff_type,:remark);

	EXEC SQL COMMIT;
	return 0;

 not_found:
	makelog("debug.log","add account not  found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL ROLLBACK;
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL ROLLBACK;
	return -2;
}
int IsStaffIDExit(char * staff_id)
{
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;
	EXEC SQL SELECT staff_id FROM STAFF WHERE STAFF_ID=:staff_id;	
	return 0;
 not_found:
	makelog("debug.log","add account not  found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;	
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;	
	return -2;
}
int DelAccount(char * staff_id)
{
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;
	EXEC SQL DELETE FROM STAFF WHERE staff_id=:staff_id;
	EXEC SQL COMMIT;
	return 0;

 not_found:
	makelog("debug.log","delete account not  found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL ROLLBACK;
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL ROLLBACK;
	return -2;
}
int QueryAccount(struct staffinfomation * staffInfo,char *staffid)
{
	char staff_id[8];
	char staff_name[16];
	char staff_pwd[18];
	char remark[32];
	short sstaff_name;
	short sremark;
	short sstaff_pwd;

	memset(staff_id,0,sizeof(staff_id));
	memset(staff_name,0,sizeof(staff_name));
	memset(staff_pwd,0,sizeof(staff_pwd));
	memset(remark,0,sizeof(remark));	
	int staff_type;
	
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR	goto sqlerr;	
	makelog("debug.log","staffid=");
	makelog("debug.log",staffid);
	EXEC SQL SELECT * INTO :staff_id,:staff_name :sstaff_name,:staff_pwd :sstaff_pwd,:staff_type,:remark :sremark FROM staff WHERE staff_id=:staffid;
	makelog("debug.log","staffid==");
	makelog("debug.log",staffid);
	Trim(staff_id);
	Trim(staff_name);
	Trim(staff_pwd);
	Trim(remark);	
	strcpy(staffInfo->staff_id,staff_id);
	strcpy(staffInfo->staff_name,staff_name);
	strcpy(staffInfo->staff_pwd,staff_pwd);
	strcpy(staffInfo->remark,remark);
	staffInfo->staff_type=staff_type;
	return 0;

 not_found:
	makelog("debug.log","Query account not  found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;	
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;	
	return -2;
}
int UpdateAcc(struct staffinfomation * staffInfo,char *staffid)
{
	/*char staff_id[8];
	char staff_name[16];
	char staff_pwd[18];
	char remark[32];
	memset(staff_id,0,sizeof(staff_id));
	memset(staff_name,0,sizeof(staff_name));
	memset(staff_pwd,0,sizeof(staff_pwd));
	memset(remark,0,sizeof(remark));
	int staff_type;
	strcpy(staff_id,staffInfo->staff_id);
	strcpy(staff_name,staffInfo->staff_name);
	strcpy(staff_pwd,staffInfo->staff_pwd);
	strcpy(remark,staffInfo->remark);
	staff_type=staffInfo->staff_type;*/
	
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR goto sqlerr;
	EXEC SQL UPDATE STAFF SET staff_id=:staffInfo->staff_id,
	staff_name=:staffInfo->staff_name,staff_pwd=:staffInfo->staff_pwd,
	staff_type=:staffInfo->staff_type,remark=:staffInfo->remark 
	WHERE staff_id=:staffid;
	EXEC SQL COMMIT;
	return 0;

 not_found:
	makelog("debug.log","Update account not  found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL ROLLBACK;
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL ROLLBACK;
	return -2;
}
RecordQueryByDateProc(char * begindate,char * enddate)
{
	makelog("debug.log",begindate);
	makelog("debug.log",enddate);
	int flag=0;
	struct sale_table * saleTabInfo1=(struct sale_table *)malloc(sizeof(struct sale_table));
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR goto sqlerr;
	EXEC SQL DECLARE saleTab_cursor1 CURSOR FOR
	SELECT *  FROM sale WHERE to_char(SALE_DATE,'yyyymmdd')>=:begindate
	and to_char(SALE_DATE,'yyyymmdd')<=:enddate;
	saleInfoList.del(&saleInfoList);
	EXEC SQL OPEN saleTab_cursor1;
	
	while(1)
	{	
		EXEC SQL WHENEVER NOT FOUND GOTO not_found;
		EXEC SQL WHENEVER SQLERROR GOTO sqlerr;		
		EXEC SQL FETCH saleTab_cursor1 INTO :saleTabInfo1->sale_id,:saleTabInfo1->trans_id,
		:saleTabInfo1->staff_id,:saleTabInfo1->sale_date,:saleTabInfo1->given_sum,
		:saleTabInfo1->real_sum,:saleTabInfo1->sale_money,:saleTabInfo1->change,
		:saleTabInfo1->sale_state;
		flag=1;
		Trim(saleTabInfo1->sale_id);
		Trim(saleTabInfo1->trans_id);
		Trim(saleTabInfo1->staff_id);
		Trim(saleTabInfo1->sale_date);
		saleInfoList.insert_rear(&saleInfoList,(void *)saleTabInfo1,sizeof(struct sale_table));
	}
	free(saleTabInfo1);
	return 0;
 not_found:
	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL CLOSE saleTab_cursor1;
	if(flag==0)
	{
	makelog("debug.log","RecordQueryByDateProc account not found");	
	return 2;
	}
	free(saleTabInfo1);	
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
	EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL CLOSE saleTab_cursor1;
	free(saleTabInfo1);	
	return -2;
}
RecordQueryByStaffIDProc(char * staff_id)
{
	int flag=0;
	struct sale_table * saleTabInfo=(struct sale_table *)malloc(sizeof(struct sale_table));
	EXEC SQL WHENEVER NOT FOUND goto not_found;
	EXEC SQL WHENEVER SQLERROR goto sqlerr;
	EXEC SQL DECLARE saleTab_cursor CURSOR FOR
	SELECT *  FROM sale WHERE staff_id=:staff_id;
	saleInfoList.del(&saleInfoList);
	EXEC SQL OPEN saleTab_cursor;
	while(1)
	{	
		EXEC SQL WHENEVER NOT FOUND GOTO not_found;
		EXEC SQL WHENEVER SQLERROR GOTO sqlerr;		
		EXEC SQL FETCH saleTab_cursor INTO :saleTabInfo->sale_id,:saleTabInfo->trans_id,
		:saleTabInfo->staff_id,:saleTabInfo->sale_date,:saleTabInfo->given_sum,
		:saleTabInfo->real_sum,:saleTabInfo->sale_money,:saleTabInfo->change,
		:saleTabInfo->sale_state;
		flag=1;		
		Trim(saleTabInfo->sale_id);
		Trim(saleTabInfo->trans_id);
		Trim(saleTabInfo->staff_id);
		Trim(saleTabInfo->sale_date);
		saleInfoList.insert_rear(&saleInfoList,(void *)saleTabInfo,sizeof(struct sale_table));
	}
	free(saleTabInfo);
	return 0;
 not_found:
	makelog("debug.log","RecordQueryByStaffIDProc account not found");	
	EXEC SQL WHENEVER NOT FOUND CONTINUE;
	EXEC SQL CLOSE saleTab_cursor;
	if(flag==0)
	return 2;
	free(saleTabInfo);	
	return -1;
 sqlerr:	
	makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
	EXEC SQL WHENEVER SQLERROR CONTINUE;
	EXEC SQL CLOSE saleTab_cursor;
	free(saleTabInfo);	
	return -2;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -