📄 setfree.cpp
字号:
#if !defined( __STRING_H )
#include <String.h>
#endif // __STRING_H
#if !defined( __STDLIB_H )
#include <StdLib.h>
#endif // __STDLIB_H
#if !defined( __STDIO_H )
#include <StdIO.h>
#endif // __STDIO_H
#define Uses_Window
#define Uses_Field
#define Uses_Button
#include <ly.h>
#include "sj.h"
#include "sjcfg.h"
const
winWidth = 250,
winHeight = 36 + 5 * 30 + 36 + 8,
winLeft = 320 - winWidth / 2,
winTop = 240 - winHeight / 2 + 5,
tytlesLeft = winLeft + 12,
fieldsLeft = tytlesLeft + 50,
fieldsWidth = 175,
ttSeg1Top = winTop + 36,
fdSeg1Top = ttSeg1Top - 4,
ttSeg2Top = ttSeg1Top + 30,
fdSeg2Top = ttSeg2Top - 4,
ttSeg3Top = ttSeg2Top + 30,
fdSeg3Top = ttSeg3Top - 4,
ttSeg4Top = ttSeg3Top + 30,
fdSeg4Top = ttSeg4Top - 4,
ttSeg5Top = ttSeg4Top + 30,
fdSeg5Top = ttSeg5Top - 4,
buttonSpace = 12,
buttonTop = fdSeg5Top + 30,
btnOKLeft = winLeft + buttonSpace,
btnOKTop = buttonTop,
btnCancelLeft = 320 - 35,
btnCancelTop = buttonTop,
btnHelpLeft = winLeft + winWidth - 70 - buttonSpace,
btnHelpTop = buttonTop;
static char *szHelp[] =
{
"■最多可设置5个脱收序号段 ",
"■没有用到的序号段设为 0-0 ",
"■最小序号为1, 允许最大序号为65535",
"■序号段格式如: 1-300, 00001-00300",
NULL
};
static BOOL CheckSeg( char *szSeg, long *lSeg )
{
char *p = strchr( szSeg, '-' );
if( p == NULL ) return FALSE;
char str[ 12 ];
int nLen = p - szSeg;
memcpy( str, szSeg, nLen );
str[ nLen ] = 0;
lSeg[ 0 ] = atol( str );
strcpy( str, p + 1 );
lSeg[ 1 ] = atol( str );
if( lSeg[ 0 ] <= lSeg[ 1 ] ) return TRUE;
return FALSE;
}
void SJ::SetFree()
{
Window *win = new Window( winTop, winWidth, winHeight, "设置脱收合同号段" );
const flSeg = 11;
static char szFormat[] = "%05lu-%05lu";
win->DrawTytle( tytlesLeft, ttSeg1Top, "段1", 'A' );
char szSeg1[ flSeg + 1 ];
sprintf( szSeg1, szFormat, config.lFree[ 0 ][ 0 ], config.lFree[ 0 ][ 1 ] );
Field *fdSeg1 = new Field( fieldsLeft, fdSeg1Top, fieldsWidth, szSeg1, flSeg );
win->DrawTytle( tytlesLeft, ttSeg2Top, "段2", 'B' );
char szSeg2[ flSeg + 1 ];
sprintf( szSeg2, szFormat, config.lFree[ 1 ][ 0 ], config.lFree[ 1 ][ 1 ] );
Field *fdSeg2 = new Field( fieldsLeft, fdSeg2Top, fieldsWidth, szSeg2, flSeg );
win->DrawTytle( tytlesLeft, ttSeg3Top, "段3", 'C' );
char szSeg3[ flSeg + 1 ];
sprintf( szSeg3, szFormat, config.lFree[ 2 ][ 0 ], config.lFree[ 2 ][ 1 ] );
Field *fdSeg3 = new Field( fieldsLeft, fdSeg3Top, fieldsWidth, szSeg3, flSeg );
win->DrawTytle( tytlesLeft, ttSeg4Top, "段4", 'D' );
char szSeg4[ flSeg + 1 ];
sprintf( szSeg4, szFormat, config.lFree[ 3 ][ 0 ], config.lFree[ 3 ][ 1 ] );
Field *fdSeg4 = new Field( fieldsLeft, fdSeg4Top, fieldsWidth, szSeg4, flSeg );
win->DrawTytle( tytlesLeft, ttSeg5Top, "段5", 'E' );
char szSeg5[ flSeg + 1 ];
sprintf( szSeg5, szFormat, config.lFree[ 4 ][ 0 ], config.lFree[ 4 ][ 1 ] );
Field *fdSeg5 = new Field( fieldsLeft, fdSeg5Top, fieldsWidth, szSeg5, flSeg );
Button *btnOK = new Button( btnOKLeft, btnOKTop, tpOkButton );
Button *btnCancel = new Button( btnCancelLeft, btnCancelTop, tpCancelButton );
Button *btnHelp = new Button( btnHelpLeft, btnHelpTop, tpHelpButton );
win->Insert( fdSeg1, fdSeg2, fdSeg3, fdSeg4, fdSeg5,
btnOK, btnCancel, btnHelp, NULL );
for(;;)
{
Event event;
while( !GetEvent( event ) );
win->HandleEvent( event );
if( event.what == evCommand )
{
if( event.command == cmOk )
{
if( *szSeg1 == ' ' ) { win->Reselect( fdSeg1 ); continue; } if( *szSeg1 == ' ' ) { win->Reselect( fdSeg1 ); continue; }
if( *szSeg2 == ' ' ) { win->Reselect( fdSeg2 ); continue; }
if( *szSeg3 == ' ' ) { win->Reselect( fdSeg3 ); continue; }
if( *szSeg4 == ' ' ) { win->Reselect( fdSeg4 ); continue; }
if( *szSeg5 == ' ' ) { win->Reselect( fdSeg5 ); continue; }
long lTmp[ 5 ][ 2 ];
if( CheckSeg( szSeg1, lTmp[ 0 ] ) &&
CheckSeg( szSeg2, lTmp[ 1 ] ) &&
CheckSeg( szSeg3, lTmp[ 2 ] ) &&
CheckSeg( szSeg4, lTmp[ 3 ] ) &&
CheckSeg( szSeg5, lTmp[ 4 ] ) )
{
memcpy( config.lFree, lTmp, 10 * sizeof( long ) );
SaveConfig();
break;
}
else
{
ShowError( "存在错误的序号段" );
win->Reselect( fdSeg1 );
}
}
else if( event.command == cmCancel ||
event.command == cmClose ) break;
else if( event.command == cmHelp )
{
ShowHelp( szHelp );
win->Reselect( fdSeg1 );
}
}
}
delete win;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -