📄 regduty.cpp
字号:
#if !defined( __STRING_H )
#include <String.h>
#endif // __STRING_H
#if !defined( __GRAPHICS_H )
#include <Graphics.h>
#endif // __GRAPHICS_H
#define Uses_DBase
#define Uses_Window
#define Uses_Field
#define Uses_Button
#include <ly.h>
#include "sj.h"
#include "sjdbf.h"
const
setWinLeft = 195,
setWinTop = 125,
setWinWidth = 250,
setWinDeapth = 233,
tytleWidth = 66,
fieldWidth = 159,
ttDutyLeft = setWinLeft + 12,
ttDutyTop = setWinTop + 68,
fdDutyLeft = ttDutyLeft + tytleWidth,
fdDutyTop = ttDutyTop - 4,
fdDutyWidth = fieldWidth,
ttPassLeft = ttDutyLeft,
ttPassTop = fdDutyTop + 40,
fdPassLeft = ttPassLeft + tytleWidth,
fdPassTop = ttPassTop - 4,
fdPassWidth = fieldWidth,
buttonSpace = 12,
buttonWidth = 70,
buttonHeight = 36,
buttonTop = fdPassTop + 37,
btnAddLeft = setWinLeft + buttonSpace,
btnAddTop = buttonTop,
btnDelLeft = 320 - buttonWidth / 2,
btnDelTop = buttonTop,
btnPrintLeft = setWinLeft + setWinWidth - buttonWidth - buttonSpace,
btnPrintTop = buttonTop,
btnExitLeft = btnAddLeft,
btnExitTop = btnAddTop + buttonHeight + buttonSpace,
btnHelpLeft = btnPrintLeft,
btnHelpTop = btnExitTop;
static char *szHelp[] =
{
"■没有登记的收款员不能进行收款操作",
" 收款员工号最多为4位数 ",
"■每个收款员都有相应的操作密码 ",
" 密码最多为6个字母,大小写均可 ",
"■收款员可以逐个添加或删除,按Enter",
" 或选择〔添加〕添加,按<F2>或选择",
" 〔删除〕删除 ",
"■按<F3>或选择〔打印〕打印收款员与",
" 密码对照表,务必注意保密 ",
"■按Esc或选择〔退出〕退出 ",
NULL
};
void SJ::ShowDuty()
{
const dutyTop = setWinTop + 26,
dutyLeft = setWinLeft + 6,
dutyRight = dutyLeft + 7 * 34,
dutyBottom = dutyTop + 2 * 10;
HideCursor();
bar( dutyLeft, dutyTop, dutyRight, dutyBottom );
::setcolor( 2 );
for( int i = 0, y = dutyTop; i < 3; i++, y += 10 )
::line( dutyLeft, y, dutyRight, y );
for( int j = 0, x = dutyLeft; j < 8; j++, x += 34 )
::line( x, dutyTop, x, dutyBottom );
char str[ flDuty + 1];
str[ flDuty ]=0;
::setcolor( 0 );
for( i = 0; i < dbfDuty->GetRecordNum() && i < 10; i++ )
{
x = dutyLeft + 2 + ( i % 7 ) * 34;
y = dutyTop + 2 + ( i / 7 ) * 10;
memcpy( str, dbfDuty->GetField( i, 0 ), flDuty );
::outtextxy( x, y, str );
}
ShowCursor();
}
void SJ::RegisterDuty()
{
Window *setWin = new Window( setWinTop, setWinWidth, setWinDeapth, "登记收款员" );
setWin->DrawTytle( ttDutyLeft, ttDutyTop, "收款员", 'S' );
char szDuty[ flDuty + 1 ];
memset( szDuty, ' ', flDuty );
szDuty[ flDuty ] = 0;
Field *fdDutyNum = new Field( fdDutyLeft, fdDutyTop, fdDutyWidth, szDuty, flDuty );
setWin->DrawTytle( ttPassLeft, ttPassTop, " 密码", 'M' );
char szPassword[ flPassword + 1 ];
memset( szPassword, ' ', flPassword );
szPassword[ flPassword ] = 0;
Field *fdPass = new Field( fdPassLeft, fdPassTop, fdPassWidth, szPassword, flPassword, tpPassword );
enum
{
cmAdd = 0x1111,
cmDel,
};
Button *btnAdd = new Button( btnAddLeft, btnAddTop, "添加", cmAdd, buttonWidth, buttonHeight );
Button *btnDel = new Button( btnDelLeft, btnDelTop, "删除", cmDel, buttonWidth, buttonHeight );
Button *btnPrint = new Button( btnPrintLeft, btnPrintTop, szBtnPrint, cmPrint, buttonWidth, buttonHeight );
Button *btnExit = new Button( btnExitLeft, btnExitTop, szBtnExit, cmExit, buttonWidth, buttonHeight );
Button *btnHelp = new Button( btnHelpLeft, btnHelpTop, tpHelpButton );
setWin->Insert( fdDutyNum, fdPass,
btnAdd, btnDel, btnPrint,
btnExit, btnHelp, NULL );
::ShowStatus( "~CF1~0帮助 ~CF2~0删除 ~CF3~0打印 ~CESC~0退出" );
ShowDuty();
Event event;
for(;;)
{
while( !GetEvent( event ) );
setWin->HandleEvent( event );
if( event.what == evKeyboard && event.key == kbF2 )
{
event.what = evCommand;
event.command = cmDel;
}
else if( event.what == evKeyboard && event.key == kbF3 )
{
event.what = evCommand;
event.command = cmPrint;
}
if( event.what == evCommand )
{
if( event.command == cmAdd || event.command == cmOk )
{
if( *szDuty != ' ' && *szPassword == ' ' )
{
setWin->Reselect( fdPass );
continue;
}
else if( *szDuty == ' ' )
{
setWin->Reselect( fdDutyNum );
continue;
}
else if( CheckDuty( szDuty ) && SurePassword( szPassword ) )
{
TransferPassword( szPassword );
int nRecNum = dbfDuty->Seek( szDuty );
if( nRecNum >= 0 )
{
ShowError( "工号存在, 原来的密码被替换" );
dbfDuty->Replace( nRecNum, fdPassword, szPassword );
}
else
{
dbfDuty->AppendRecord( szDuty, szPassword );
ShowDuty();
dbfDuty->SaveData();
}
}
fdDutyNum->Clear();
fdPass->Clear();
setWin->Reselect( fdDutyNum );
}
else if( event.command == cmDel )
{
if( *szDuty == ' ' )
{
setWin->Reselect( fdDutyNum );
continue;
}
int nRecNum = dbfDuty->Seek( szDuty );
if( nRecNum >= 0 )
{
dbfDuty->DeleteRecord( nRecNum );
ShowDuty();
dbfDuty->SaveData();
}
else ShowError( "没有这个工号" );
fdDutyNum->Clear();
fdPass->Clear();
setWin->Reselect( fdDutyNum );
}
else if( event.command == cmPrint )
{
if( !PrnReady() )
{
setWin->Reselect( fdDutyNum );
continue;
}
for( int i = 0; i < dbfDuty->GetRecordNum(); i ++ )
{
dbfDuty->GetField( i, fdDuty, szDuty );
szDuty[ flDuty ] = 0;
dbfDuty->GetField( i, fdPassword, szPassword );
TransferPassword( szPassword );
szPassword[ flPassword ] = 0;
fprintf( stdprn, "%s----- %s\n", szDuty, szPassword );
}
NewPage();
fdDutyNum->Clear();
fdPass->Clear();
setWin->Reselect( fdDutyNum );
}
else if( event.command == cmExit ||
event.command == cmCancel ||
event.command == cmClose ) break;
else if( event.command == cmHelp )
{
ShowHelp( szHelp );
setWin->Reselect( fdDutyNum );
}
}
}
delete setWin;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -