#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "public.h"
#include "protime.h"
#include "screen.h"
#include "mymenu.h"
#include "myform.h"
#include "global.h"
#include "clitype.h"
#include "viewbox.h"
extern int SendHost();
void ErrLog(const char *fmt, ...)
{
va_list ap_list;
FILE *fp;
char fname[30];
va_start(ap_list, fmt);
memset(fname,0,30);
sprintf(fname,"../log/ErrCli.%d",GetSysTime('D'));
fp = fopen(fname,"a+");
if (fp != NULL)
{
fprintf(fp,"[%06d] ",GetSysTime('T'));
vfprintf(fp, fmt, ap_list);
fflush(fp);
fclose(fp);
}
va_end(ap_list);
}
int ChkPrivil(char type)//检查用户权限
{
if(OPRTYPE[0] != type) {
PrintErr(stdscr, 1009);
deleteln();
refresh();
return(1);
}
return(0);
}
/*
增加柜员
发送: 1001
oprcode char(4) not null,
oprname char(12) not null,
oprtype char(1) not null,
passwd char(6) not null,
orgcode char(4) not null,
stat char(1) not null
返回:1001 + 结果
0-存在 !0-失败
*/
int AddUser()
{
char oprcode[5], oprname[13];
char tmp[5];
int ret = 0;
FORM_NODE *p;
WINDOW *win;
if(ChkPrivil('2')) return(1);
if((p = LoadForm("../etc/adduser.frm")) == NULL) return(0);
win = FormWin(p);
while(DriverForm(p) == OK ){
if(CheckForm(p)) continue;
memset(PACK, 0, sizeof(PACK));
sprintf(PACK, "1001%-4s%-12s%s%-6s%-4s0",
ReadField(p, 1), ReadField(p, 2), ReadField(p, 3),
ReadField(p, 4), ReadField(p, 5));
if(ret = SendHost()) PrintErr(win, ret);
else {
memset(tmp, 0, 5);
memcpy(tmp, &PACK[4], 4);
if( ret = atoi(tmp)) PrintErr(win, ret);
else {
PrintMsg(win, "增加柜员成功", 'R');
FreeForm(p);
p = LoadForm("../etc/adduser.frm");
win = FormWin(p);
}
}
}
FreeForm(p);
return(ret);
}
/*
SEND:删除柜员 1002
oprcode
GET: 1002 + result
*/
int DelUser()
{
char oprcode[5], oprname[13];
char tmp[5];
int ret = 0;
FORM_NODE *p;
WINDOW *win;
if(ChkPrivil('2')) return(1);
if((p = LoadForm("../etc/deluser.frm")) == NULL) return(0);
win = FormWin(p);
while(DriverForm(p) == OK ){
if(CheckForm(p)) continue;
memset(PACK, 0, sizeof(PACK));
sprintf(PACK, "1002%-4s", ReadField(p, 1));
if(ret = SendHost()) PrintErr(win, ret);
else {
memset(tmp, 0, 5);
memcpy(tmp, &PACK[4], 4);
if( ret = atoi(tmp)) PrintErr(win, ret);
else {
PrintMsg(win, "删除柜员成功", 'R');
FreeForm(p);
p = LoadForm("../etc/deluser.frm");
win = FormWin(p);
}
}
}
FreeForm(p);
return(ret);
}
int QryUser()
{
int ret, i;
char name[80], title[1024], lname[40], rname[40], tmp[5], cmd[160];
if(ChkPrivil('2')) return(1);
memset(PACK, 0, sizeof(PACK));
sprintf(PACK, "1003%-8s%-4s", SYSDATE, OPRCODE);
if(ret = SendHost()) {
PrintErr(stdscr, ret);
deleteln();
refresh();
return(-1);
}
memset(tmp, 0, 5);
memcpy(tmp, &PACK[4], 4);
if( ret = atoi(tmp)) {
PrintErr(stdscr, ret);
deleteln();
refresh();
return(-1);
}
memset(rname, 0, 40);
memset(lname, 0, 40);
sprintf(rname, "/usr/large/data/R%-4s", OPRCODE);
sprintf(lname, "/usr/large/tmp/R%-4s", OPRCODE);
memset(cmd,0,160);
sprintf(cmd,"FTPclient -h %s -p %d -a -r -f %s -F %s", IP, FTPPORT, rname, lname);
CliLog("%s|%d|命令[%s]\n",__FILE__,__LINE__,cmd);
i=0;
while(i++ < 3 && system(cmd) );
if(i>=3) {
CliLog("%s|%d|下载文件[%s]失败\n",__FILE__,__LINE__,rname);
PrintMsg(stdscr, "下载文件失败", 'E');
deleteln();
refresh();
return(-1);
}
memset(name, 0, sizeof(name));
sprintf(name, "%s", "[查询柜员]");
memset(title, 0, sizeof(title));
sprintf(title, "%-6s %-12s %-8s %-4s %-4s",
"柜员号","姓名","类别","所号","状态");
ViewBox(2, 2, 22, 76, name, title, lname);
return(0);
}
int ModiPass()//修改密码
{
int ret = 0;
FORM_NODE *p;
WINDOW *win;
char tmp[80];
if((p = LoadForm("../etc/modipass.frm")) == NULL) return(0);
win = FormWin(p);
WriteField(p, 1, ORGCODE);
while(DriverForm(p) == OK ) {
if(strcmp(Trim(ReadField(p, 2)), Trim(ReadField(p, 3)))) {
PrintMsg(win, "新密码两次输入不同", 'E');
continue;
}
memset(PACK, 0, sizeof(PACK));
sprintf(PACK, "1008%4s%-6s",OPRCODE, ReadField(p, 2));
if(ret = SendHost()) PrintErr(win, ret);
else {
memset(tmp, 0, 80);
memcpy(tmp, &PACK[4], 4);
if( ret = atoi(tmp)) PrintErr(win, ret);
else {
PrintMsg(win, "密码修改成功", 'R');
FreeForm(p);
return(0);
}
}
}
FreeForm(p);
return(ret);
}
int UserExit()//柜员签退
{
int ret;
char code[5];
memset(PACK, 0, sizeof(PACK));
sprintf(PACK, "1005%-4s", OPRCODE);
if(ret = SendHost()) {
PrintErr(stdscr, ret);
deleteln();
refresh();
return(1);
}
memset(code, 0, 5);
memcpy(code, &PACK[4], 4);
if( ret = atoi(code)) {
PrintErr(stdscr, ret);
deleteln();
refresh();
return(1);
}
EndScreen();
CancelType();
exit(0);
}
/*
大额转账业务要素检查
*/
int ChkHVPT(FORM_NODE *p)
{
ST_HVPT m;
char tmp[80];
WINDOW *win=FormWin(p);
memset(&m, 0, sizeof(ST_HVPT));
strcpy(m.outbkno, ReadField(p, 1));
strcpy(m.outbktype, ReadField(p, 2));
strcpy(m.outname, ReadField(p, 3));
strcpy(m.outacctno, ReadField(p, 4));
strcpy(m.outpartno, ReadField(p, 5));
strcpy(m.inbkno, ReadField(p, 6));
strcpy(m.inbktype, ReadField(p, 7));
strcpy(m.inname, ReadField(p, 8));
strcpy(m.inacctno, ReadField(p, 9));
strcpy(m.inpartno, ReadField(p, 10));
memset(tmp, 0, 80);
strcpy(tmp, ReadField(p, 11));
m.amount = atof(tmp);
strcpy(m.outdate, ReadField(p, 12));
strcpy(m.indate, ReadField(p, 13));
strcpy(m.use, ReadField(p, 14));
strcpy(m.transtype, ReadField(p, 15));
strcpy(m.billno, ReadField(p, 16));
strcpy(m.transcode, ReadField(p, 17));
if(IsBlank(m.outbkno)) {
PrintMsg(win, "付款行行号不能为空", 'E');
return(1);
}
if(atoi(m.transtype) != 51 ) {
if(IsBlank(m.outacctno)) {
PrintMsg(win, "当结算方式不为银行本票时,付款人账号不能为空。", 'E');
return(1);
}
}
if(atoi(m.transtype) != 51 ) {
if(IsBlank(m.outname)) {
PrintMsg(win, "当结算方式不为银行本票时,付款人名称不能为空。", 'E');
return(1);
}
}
if(IsBlank(m.inbkno)) {
PrintMsg(win, "收款行行号不能为空", 'E');
return(1);
}
if(IsBlank(m.inacctno)) {
PrintMsg(win, "收款人账号不能为空", 'E');
return(1);
}
if(IsBlank(m.inname)) {
PrintMsg(win, "收款人名称不能为空", 'E');
return(1);
}
if((m.inbktype[0] != '0') || (m.outbktype[0] != '0')) {
if(IsBlank(m.billno)) {
PrintMsg(win, "跨行交易时凭证代码不能为空", 'E');
return(1);
}
}
if(((m.inbktype[0] == '0' ) && (m.outbktype[0] != '0'))
|| ((m.inbktype[0] !='0') && (m.outbktype[0] == '0')))
{
PrintMsg(win, "收、付款行行号类型不一致。", 'E');
return(1);
}
return(0);
}
/*
大额转账业务
*/
int AddHVPT()
{
int ret = 0;
FORM_NODE *p;
WINDOW *win;
char tmp[80];
if(ChkPrivil('1')) return(1);
if((p = LoadForm("../etc/addhvpt.frm")) == NULL) return(0);
win = FormWin(p);
while(DriverForm(p) == OK ){
if(CheckForm(p)) continue;
if(ChkHVPT(p)) continue;
memset(PACK, 0, sizeof(PACK));
sprintf(PACK, "2001%-8s%-4s%-06d%-32s%-12s%s%-60s%-40s%-20s%-12s%s%-60s%-40s%-20s%-18s%-8s%-8s%-20s%-2s%-32s%-10s%-20s%-4s%s",
SYSDATE, OPRCODE, SEQNO++, " ",
ReadField(p, 1), ReadField(p, 2), ReadField(p, 3),
ReadField(p, 4), ReadField(p, 5), ReadField(p, 6),
ReadField(p, 7), ReadField(p, 8), ReadField(p, 9),
ReadField(p, 10), ReadField(p, 11), ReadField(p, 12),
ReadField(p, 13), ReadField(p, 14), ReadField(p, 15),
ReadField(p, 16), ReadField(p, 17), " ", ORGCODE, "1");
if(ret = SendHost()) PrintErr(win, ret);
else {
memset(tmp, 0, 80);
memcpy(tmp, &PACK[4], 4);
if( ret = atoi(tmp)) PrintErr(win, ret);
else {
PrintMsg(win, "交易成功", 'R');
FreeForm(p);
p = LoadForm("../etc/addhvpt.frm");
win = FormWin(p)