第二阶段pos中的.PC文件

 int flag=0;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL WHENEVER NOT FOUND goto notfound;
 EXEC SQL   
  select bar_code,product_name,unit,spec,sale_price,purchase_price,num,discount,flag
  INTO :temp->code,
  :temp->name, 
  :temp->unit,
  :temp->type,
  :temp->unit_price ,
  :temp->buy_price,
  :temp->quantity,
  :temp->discount,
  :temp->delete_tag
  FROM PRODUCT
  WHERE bar_CODE=:code;
  
  rtrim(temp->code);
  rtrim(temp->name);
  rtrim(temp->type);
  rtrim(temp->unit);
 EXEC SQL WHENEVER SQLERROR goto error;
 flag = 1; 
 return 0;
notfound:
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 if (sqlca.sqlerrd[2]>0)
 {
  makelog("debug.log","db_show succ");
  
  return 0;
 }
 makelog("debug.log","db_show no data found");
 
 return 1;
error:
 makelog("debug.log","db_show");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 EXEC SQL WHENEVER SQLERROR CONTINUE;
 if (flag)
  
 return 2;
}

 

 

void get_db_time(char *dbtime)

 EXEC SQL BEGIN DECLARE SECTION;
 varchar time[15];
 EXEC SQL end declare section;
 EXEC SQL SELECT TO_CHAR(SYSDATE,'YYYYMMDDHH24MISS') INTo :time
 FROM DUAL;
 time.arr[time.len]='\0';
 strcpy(dbtime,time.arr);

}

int get_name(char *account,char *passwd,char name[])
{
 EXEC SQL BEGIN DECLARE SECTION;
 varchar dbname[7];
 int type;
 EXEC SQL END DECLARE SECTION;
 EXEC SQL WHENEVER NOT FOUND GOTO NOFOUND;
 EXEC SQL WHENEVER SQLERROR GOTO ERROR;
 EXEC SQL
 SELECT  STAFF_NAME,STAFF_TYPE  INTo :dbname, :type
 FROM STAFF
 WHERE STAFF_ID=:account and STAFF_PWD=:passwd;
 dbname.arr[dbname.len]='\0';
 strcpy(name,dbname.arr);
 return type;
ERROR:
 makelog("debug.log","db_show");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 EXEC SQL WHENEVER SQLERROR CONTINUE;
 return 6;
NOFOUND:
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 makelog("debug.log","db_show no data found");
 return 7;
 
}


int check_login(char account[],char passwd[])
{
 EXEC SQL BEGIN DECLARE SECTION;
 varchar tempname[7]={0},temppwd[13]={0};
 int type,tempflag;
 EXEC SQL END DECLARE SECTION;
 int len,i;
 len=strlen(account);
 if(len<6)
  return 3;
 for(i=0;i<len;i++)
 {
  if(!isdigit(account[i]))
   return 4;
 }
 len=strlen(passwd);
 if(len<6||len>12)
  return 5;
 for(i=0;i<len;i++)
 {
  if(!isprint(passwd[i]))
   return 6;
 }
 EXEC SQL WHENEVER NOT FOUND GOTO NOFOUND;
 EXEC SQL
 SELECT STAFF_ID,STAFF_PWD,STAFF_TYPE,FLAG INTO :tempname,:temppwd, :type,:tempflag
 FROM STAFF
 WHERE STAFF_ID=:account;
 tempname.arr[tempname.len]='\0';
 temppwd.arr[temppwd.len]='\0';
 rtrim(tempname.arr);
 rtrim(temppwd.arr);

 /*if(tempname.len==0)
 return 7;*/
 if(tempflag==1)
 return -1;
  if(strcmp(passwd,temppwd.arr)!=0)
 return 9;

 else if(type==1)
 return 8;

 else if(type==2)
 return 10;

NOFOUND:
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 makelog("debug.log","db_show no data found");
 return 7;
 
}


int make_seq()
{
 EXEC SQL BEGIN DECLARE SECTION;
 int temp;
 EXEC SQL END DECLARE SECTION;
 EXEC SQL WHENEVER SQLERROR GOTO ERROR;

 EXEC SQL
 SELECT SEQ_TRANS_ID.NEXTVAL INTO :temp from dual;
 return temp;

 

ERROR:
 makelog("debug.log","db_show");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
}

void make_form_num(char *str1,char str2[],char date[])
{
 char temp[15];
 strcpy(temp,str1);
 strcpy(date,strcat(temp,str2));

}

void inser_detail_to_db()
{
 NODE *p;
 int sale_detail_id;
 int count;
 char code[9];
 float unit_price;
 p=templink.head->next;
 while(p!=NULL)
 {
  strcpy(code,  ((SHOP *) p->data)->code);
  unit_price=  ((SHOP *) p->data)->unit_price;
  count=  ((SHOP *) p->data)->quantity;
  EXEC SQL WHENEVER SQLERROR GOTO ERROR;
  EXEC SQL
  SELECT  SEQ_DETAIL_ID.NEXTVAL INTO :sale_detail_id from dual;
  EXEC SQL INSERT INTO  SALE_DETAIL VALUES(:sale_detail_id,:date,:code,:count,:unit_price);
  
  p=p->next;
  
  
 }
 EXEC SQL COMMIT WORK;
ERROR:
 makelog("debug.log","db_show");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);


}

 

void insert_sale_to_db(char *str,float tm)
{
 char tmp[100]={0};
 sprintf(tmp,"tm=%f real_take=%s",tm,real_take);
 makelog("debug.log",tmp);
 char time[30]={0};
 float give_money;
 float rest;
 strcpy(time,str);
 give_money=atof(real_take);
 rest=give_money-tm;
 EXEC SQL WHENEVER SQLERROR GOTO ERROR;
 EXEC SQL INSERT INTO SALE VALUES(:date,:account,to_date(:time,'YYYYMMDDHH24MISS'),:tm,:give_money,:rest);
 EXEC SQL COMMIT WORK;
 return;

ERROR:
 makelog("debug.log","db_show");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);

}

void update_db()
{
 NODE* p;
 p=templink.head->next;
 int count;
 int dbcount;
 char code[9];
 EXEC SQL WHENEVER SQLERROR GOTO ERROR;
 while(p!=NULL)
 {
  
  
  count=((SHOP *)p->data)->quantity;
  strcpy(code,((SHOP *)p->data)->code);
  
  EXEC SQL
  SELECT NUM INTO :dbcount FROM PRODUCT
  WHERE BAR_CODE=:code;
  if(dbcount==count)
  {
   EXEC SQL
   UPDATE PRODUCT
   SET FLAG=1,NUM=0
   WHERE BAR_CODE=:code;
  }
  else if(dbcount>count)
  {
  EXEC SQL
  UPDATE PRODUCT
  SET NUM=:dbcount-:count
  WHERE BAR_CODE=:code;
  }
  
  p=p->next;
  
 }
 EXEC SQL COMMIT WORK;
 return;
ERROR:
 makelog("debug.log","tmp");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);

  

}


void insert_good(char code[],char name[],char unit[],char type[],float sell,float buy,int num,float disc,int tag)
{
 EXEC SQL WHENEVER SQLERROR GOTO ERROR;
 EXEC SQL INSERT INTO PRODUCT VALUES(:code,:name,:unit,:type,:sell,:buy,:num,:disc,:tag);
 EXEC SQL COMMIT WORK;
 return;

ERROR:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);


}
void insert_staff(char staff_id[],char staff_name[],char staff_pwd[],int staff_type,int flag,char remark[])
{

EXEC SQL WHENEVER SQLERROR GOTO ERROR;
 EXEC SQL INSERT INTO STAFF VALUES(:staff_id,:staff_name,:staff_pwd,:staff_type,:flag,:remark);
 EXEC SQL COMMIT WORK;
 return;

ERROR:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);


}


int  chek_staff_in_db(char code[])
{

 EXEC SQL WHENEVER SQLERROR GOTO ERROR;
 EXEC SQL WHENEVER NOT FOUND goto notfound;
 EXEC SQL
 SELECT STAFF_ID FROM STAFF
 WHERE STAFF_ID=:code;
 return 1;


notfound:
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 makelog("debug.log"," no data found");
 return 0;

ERROR:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 return 2;


}


int staff_into_link()
{
 init_link(&tempstaff);
 char staff_id[7];
 char staff_name[15];
 char staff_pwd[13];
 int staff_type;
 char remark[20];
 int flag;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL DECLARE staff_cur CURSOR FOR
  SELECT STAFF_ID,STAFF_NAME,STAFF_PWD,STAFF_TYPE,FLAG,REMARK FROM STAFF;

 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL OPEN staff_cur;
 while (1)
 {
  EXEC SQL WHENEVER NOT FOUND goto notfound;
  EXEC SQL WHENEVER SQLERROR goto error;
  EXEC SQL FETCH staff_cur into :staff_id,:staff_name,:staff_pwd,:staff_type,:flag,:remark;
  rtrim(staff_id);
  rtrim(staff_name);
  rtrim(staff_pwd);
  rtrim(remark);
  strcpy(staff1.staff_id,staff_id);
  strcpy(staff1.staff_name,staff_name);
  strcpy(staff1.staff_pwd,staff_pwd);
  strcpy(staff1.remark,remark);
  staff1.flag=flag;
  staff1.staff_type=staff_type;
  insert_node_tail(&tempstaff, (void *)&staff1, sizeof(STAFF));
  
  
 }

error:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 return 2;
notfound:
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 makelog("debug.log"," no data found");
 return 0;


 
 
}


int create_staff_id()
{
  int a;
  EXEC SQL WHENEVER SQLERROR GOTO error;
  EXEC SQL
  SELECT  SEQ_STAFF_ID.NEXTVAL INTO :a from dual;
  return a;


error:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 return 2;

}

int find_change_staff()
{
 char staff_id[7];
 char staff_name[15];
 char staff_pwd[13];
 int staff_type;
 char remark[20];
 int flag;
 EXEC SQL WHENEVER SQLERROR GOTO error;
 EXEC SQL
 SELECT STAFF_ID,STAFF_NAME,STAFF_PWD,STAFF_TYPE,FLAG,REMARK INTO :staff_id,
 :staff_name,:staff_pwd,:staff_type,:flag,:remark FROM STAFF
 WHERE STAFF_ID=:idnum;
 rtrim(staff_id);
 rtrim(staff_name);
 rtrim(staff_pwd);
 rtrim(remark);

 strcpy(staff2.staff_id,staff_id);
 strcpy(staff2.staff_name,staff_name);
 strcpy(staff2.staff_pwd,staff_pwd);
 strcpy(staff2.remark,remark);
 staff2.flag=flag;
 staff2.staff_type=staff_type;
 
error:

 makelog("debug.log",remark);
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 return 2;
}


int upate_staff()
{
 char staff_id[7]={0};
 char staff_name[20]={0};
 int staff_type;
 char staff_pwd[13]={0};  
 char remark[20]={0};
 int staff_flag;

 strcpy(staff_id,staff2.staff_id);
 strcpy(staff_name,staff2.staff_name);
 staff_type=staff2.staff_type;
 strcpy(staff_pwd,staff2.staff_pwd);
 strcpy(remark,staff2.remark);
 staff_flag=staff2.flag;
 
 EXEC SQL WHENEVER SQLERROR GOTO error;
 EXEC SQL
 UPDATE STAFF
 SET STAFF_ID=:staff_id,STAFF_NAME=:staff_name,STAFF_PWD=:staff_pwd,STAFF_TYPE
 =:staff_type,REMARK=:remark
 WHERE STAFF_ID=:staff_id;
 EXEC SQL COMMIT WORK;

error:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 return 2;
}
int del_user()
{
 char staff_code[7]={0};
 strcpy(staff_code,staff2.staff_id);
 EXEC SQL WHENEVER SQLERROR GOTO error;
 EXEC SQL
 UPDATE STAFF
 SET FLAG=1
 WHERE STAFF_ID=:staff_code;
 /*DELETE FROM STAFF
 WHERE STAFF_ID=:staff_code;*/
 EXEC SQL COMMIT WORK;

error:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 return 2;
}

int sear_form()
{
 char sale_id[20];
 char staff_id[10];
 char sale_date[13];
  float pay_sum;
  float real_sum;
  float change;
  init_link(&sale);

 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL DECLARE sale_cur CURSOR FOR
 SELECT SALE_ID,STAFF_ID,TO_CHAR(SALE_DATE,'YYYYMMDD'),PAY_SUM,REAL_SUM,CHANGE FROM SALE
 WHERE TO_CHAR(SALE_DATE,'YYYYMMDD') BETWEEN :begin_date and :end_date;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL OPEN sale_cur;
 while (1)
 {
 
 EXEC SQL WHENEVER NOT FOUND goto notfound;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL FETCH sale_cur into :sale_id,:staff_id,:sale_date,:pay_sum,:real_sum,:change;
 rtrim(sale_id);
 rtrim(staff_id);
 rtrim(sale_date);
 
 strcpy(sale1.sale_id,sale_id);
 strcpy(sale1.staff_id,staff_id);
 strcpy(sale1.sale_date,sale_date);
 sale1.pay_sum=pay_sum;
 sale1.real_sum=real_sum;
 sale1.change=change;
 insert_node_tail(&sale, (void *)&sale1, sizeof(SALE));
  
 }
 EXEC SQL CLOSE sale_cur;
 return 0;

error:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 EXEC SQL CLOSE sale_cur;
 return 2;

notfound:
 
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 if (sqlca.sqlerrd[2]>0)
 {
  makelog("debug.log"," succ");
  
  return 0;
 }
 makelog("debug.log"," no data found");
 
 return 1;


   }

 

int sear_sale_all()
{
 char sale_id[20];
 char staff_id[10];
 char sale_date[13];
  float pay_sum;
  float real_sum;
  float change;
  init_link(&sale_tot);

 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL DECLARE sale_all_cur CURSOR FOR
 SELECT SALE_ID,STAFF_ID,TO_CHAR(SALE_DATE,'YYYYMMDD'),PAY_SUM,REAL_SUM,CHANGE FROM SALE;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL OPEN sale_all_cur;
 while (1)
 {
 
 EXEC SQL WHENEVER NOT FOUND goto notfound;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL FETCH sale_all_cur into :sale_id,:staff_id,:sale_date,:pay_sum,:real_sum,:change;
 rtrim(sale_id);
 rtrim(staff_id);
 rtrim(sale_date);
 
 strcpy(sale_all.sale_id,sale_id);
 strcpy(sale_all.staff_id,staff_id);
 strcpy(sale_all.sale_date,sale_date);
 sale_all.pay_sum=pay_sum;
 sale_all.real_sum=real_sum;
 sale_all.change=change;
 insert_node_tail(&sale_tot, (void *)&sale_all, sizeof(SALE));
  
 }
 EXEC SQL CLOSE sale_all_cur;
 return 1;

error:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 EXEC SQL CLOSE sale_all_cur;
 return 2;

notfound:
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 makelog("debug.log"," no data found");
 EXEC SQL CLOSE sale_all_cur;
 return 0;
   }

 


int find_by_id()
{
 char sale_id[20];
 char staff_id[10];
 char sale_date[13];
  float pay_sum;
  float real_sum;
  float change;
  init_link(&idserch);

 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL DECLARE find_id_cur CURSOR FOR
 SELECT SALE_ID,STAFF_ID,TO_CHAR(SALE_DATE,'YYYYMMDD'),PAY_SUM,REAL_SUM,CHANGE FROM SALE
 WHERE STAFF_ID=:find_staff_id;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL OPEN find_id_cur;
 while (1)
 {
 
 EXEC SQL WHENEVER NOT FOUND goto notfound;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL FETCH find_id_cur into :sale_id,:staff_id,:sale_date,:pay_sum,:real_sum,:change;
 rtrim(sale_id);
 rtrim(staff_id);
 rtrim(sale_date);
 
 strcpy(sale_all.sale_id,sale_id);
 strcpy(sale_all.staff_id,staff_id);
 strcpy(sale_all.sale_date,sale_date);
 sale_all.pay_sum=pay_sum;
 sale_all.real_sum=real_sum;
 sale_all.change=change;
 insert_node_tail(&idserch, (void *)&sale_all, sizeof(SALE));
  
 }
 EXEC SQL CLOSE find_id_cur;
 return 0;

error:
 makelog("debug.log","");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 EXEC SQL CLOSE find_id_cur;
 return 2;

notfound:
 
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 if (sqlca.sqlerrd[2]>0)
 {
  makelog("debug.log"," succ");
  
  return 0;
 }
 makelog("debug.log","db_show no data found");
 
 return 1;

 

}

 


int find_by_tb_num()
{
 char sale_id[20];
 char staff_id[10];
 char sale_date[13];
  float pay_sum;
  float real_sum;
  float change;
  init_link(&game_over);

 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL DECLARE find_num_cur CURSOR FOR
 SELECT SALE_ID,STAFF_ID,TO_CHAR(SALE_DATE,'YYYYMMDD'),PAY_SUM,REAL_SUM,CHANGE FROM SALE
 WHERE SALE_ID= :table_num;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL OPEN find_num_cur;
 makelog("debug.log",table_num);
 while (1)
 {
 
 EXEC SQL WHENEVER NOT FOUND goto notfound;
 EXEC SQL WHENEVER SQLERROR goto error;
 EXEC SQL FETCH find_num_cur into :sale_id,:staff_id,:sale_date,:pay_sum,:real_sum,:change;
 rtrim(sale_id);
 rtrim(staff_id);
 rtrim(sale_date);
 
 strcpy(sale_all.sale_id,sale_id);
 strcpy(sale_all.staff_id,staff_id);
 strcpy(sale_all.sale_date,sale_date);
 sale_all.pay_sum=pay_sum;
 sale_all.real_sum=real_sum;
 sale_all.change=change;
 insert_node_tail(&game_over, (void *)&sale_all, sizeof(SALE));
  
 }
 EXEC SQL CLOSE find_num_cur;

 makelog("debug.log","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
 return 0;

error:
 makelog("debug.log","db_show");
 makelog("debug.log",sqlca.sqlerrm.sqlerrmc);
 EXEC SQL CLOSE find_num_cur;
 makelog("debug.log","bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
 return 2;

notfound:
 
 EXEC SQL WHENEVER NOT FOUND CONTINUE;
 if (sqlca.sqlerrd[2]>0)
 {
  makelog("debug.log","db_show succ");
  
  return 0;
 }
 makelog("debug.log","db_show no data found");
 
 return 1;

 


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值