📄 timeclientdlg.cpp
字号:
case IDD_TIMERRGTFILE://传文件:发过来一个位置,补到文件结束。
{
msg_put("OnTimer 传文件 ");
}
break;
case IDD_TIMERRENEW: //补数数:发过来一个请求,就补一条数据。
{
msg_put("ONTimer 人工台补文件");
KillTimer(IDD_TIMERRENEW);
}
break;
}
*/
CString d;
for(int z=0; z<MAX_CLIENT; z++ )//加IP
{
d=m_listClient.GetItemText(z,1);
if(d=="")//为空
{
}
}
CDialog::OnTimer(nIDEvent);
}
void CTimeClientDlg::OnDestroy()
{
CDialog::OnDestroy();
OnButtonDelete();
KillTimer(IDD_TIMER);
KillTimer(IDD_TIMER2);
KillTimer(IDD_TIMERRGTFILE);
KillTimer(IDD_TIMERRENEW);
}
void CTimeClientDlg::OnOpenApplication()
{
if(m_open_application)
{
m_open_application = FALSE;
AfxGetApp()->m_pMainWnd->ShowWindow( SW_MINIMIZE );
AfxGetApp()->m_pMainWnd->UpdateWindow();
AfxGetApp()->m_pMainWnd->ShowWindow( SW_HIDE );//SW_SHOWNORMAL SW_SHOWMAXIMIZED
AfxGetApp()->m_pMainWnd->UpdateWindow();
}
else
{
m_open_application = TRUE;
AfxGetApp()->m_pMainWnd->ShowWindow( SW_MINIMIZE );
AfxGetApp()->m_pMainWnd->UpdateWindow();
AfxGetApp()->m_pMainWnd->ShowWindow( SW_SHOWNORMAL );//SW_SHOWNORMAL SW_SHOWMAXIMIZED
AfxGetApp()->m_pMainWnd->UpdateWindow();
}
}
void CTimeClientDlg::OnApplicationExit()
{
OnButtonDelete();
KillTimer(IDD_TIMER);
KillTimer(IDD_TIMER2);
KillTimer(IDD_TIMERRGTFILE);
KillTimer(IDD_TIMERRENEW);
CDialog::OnDestroy();
CDialog::OnCancel();
CDialog::OnClose();
}
LRESULT CTimeClientDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
//Delegate all the work back to the default implementation in
//CTrayNotifyIcon.
return m_TrayIcon.OnTrayNotification(wParam, lParam);
}
void CTimeClientDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
m_open_application = FALSE;
AfxGetApp()->m_pMainWnd->ShowWindow( SW_MINIMIZE );
AfxGetApp()->m_pMainWnd->UpdateWindow();
AfxGetApp()->m_pMainWnd->ShowWindow( SW_HIDE );
AfxGetApp()->m_pMainWnd->UpdateWindow();
}
int CTimeClientDlg::OnAdddisphone(char *zjh)
{
int ret=0;
CString dhh;
dhh=zjh;
if(strlen(dhh)<2)
{
msg_put("您输入的局向号不正确");
return(0);
}
CFile handle;
DBF_HEAD dbfhead;
JZDH *c;
char filename[32];
wsprintf(filename,"d:\\tele\\jzdh.dbf");
if(!handle.Open(filename,CFile::modeReadWrite|CFile::shareDenyNone))
{
msg_put("Cannot Open d:\\tele\\jzdh.dbf open error!");
return(0);
}
handle.Seek(0,CFile::begin);
handle.Read(&dbfhead,sizeof(DBF_HEAD));
long num = dbfhead.count;
c = new JZDH[num];
if(c==NULL)
{
msg_put("not enough memory!!!");
handle.Close();
return(0);
}
handle.Seek(dbfhead.offset,CFile::begin);
if(handle.ReadHuge(c,num * sizeof(JZDH)) < 1)
{
SetWindowText("读错误!");
handle.Close();
delete c;
return(0);
}
int is=0,code_num=-1;
for(long i=0;i<num; i++)
{
c[i].s_zjh[11]=0;
for(int j=0;j<15;j++)
{
if(c[i].s_zjh[j]==0x20)
{
c[i].s_zjh[j]=0;
break;
}
}
if(memcmp(dhh,c[i].s_zjh,strlen(c[i].s_zjh)) == 0)
{
is=1;
code_num=i;
ret=2;
break;
}
}
if(code_num==-1)
{
for(i=0;i<num;i++)
{
if(memcmp("0",c[i].flag1,1) == 0)
{
is=1;
code_num=i;
ret=1;
break;
}
}
}
if(is==1)
{
JZDH jzdh;
handle.Seek(code_num*sizeof(JZDH)+dbfhead.offset,CFile::begin);
memset(&jzdh,0x20,sizeof(JZDH));
wsprintf(jzdh.s_zjh,"%s",dhh.Right(7));
wsprintf(jzdh.flag1,"1");
handle.Write(&jzdh,sizeof(JZDH));
}
else
{
JZDH2 jzdh2;
handle.Seek(i*sizeof(JZDH)+dbfhead.offset,CFile::begin);
memset(&jzdh2,0x20,sizeof(JZDH2));
wsprintf(jzdh2.s_zjh,"%s",dhh.Right(7));
wsprintf(jzdh2.flag1,"1");
jzdh2.end_flag=0x1a;
handle.Write(&jzdh2,sizeof(JZDH2));
handle.Seek(0,CFile::begin);
handle.Read(&dbfhead,sizeof(DBF_HEAD));
dbfhead.count++;
handle.Seek(0,CFile::begin);
handle.Write(&dbfhead,sizeof(DBF_HEAD));
ret=1;
}
delete c;
handle.Close();
return(ret);
}
long CTimeClientDlg::SETMM(char *zjhc)
{
long kg=2;
long ret=0;
CString strZjh=zjhc;
CFile f_mm;
char tmp_zjh[32],fname[32];
sprintf(tmp_zjh,"%s",strZjh.Right(7));
DBF_HEAD xf_head;
sprintf(fname,"d:\\GWMS\\DBF\\mm\\%s.dbf",strZjh.Right(3));
msg_put(fname);
if(!finder.FindFile(fname))
{
CopyFile("d:\\GWMS\\DBF\\mm\\mm.dbf",fname,false);
sprintf(msg,"没有这个表%s,生成",fname);
msg_put(msg);
}
if(!f_mm.Open(fname,CFile::modeReadWrite|CFile::shareDenyNone ))
{
msg_put("Open dbf error!!! When xian_fa");
return(0);
}
f_mm.Read(&xf_head,sizeof(DBF_HEAD));
long tmp_offset = xf_head.offset;
f_mm.Seek(xf_head.offset,CFile::begin);
int is=0;
// mm=(struct GWMSMM *)bf;
long mmoffset;
GWMSMM mm;
int array=65535/sizeof(GWMSMM);
array*=sizeof(GWMSMM);
char *xx = new char[array];
unsigned int y = f_mm.Read(xx,array);
while(y)
{
for(unsigned int k = 0; k < y /sizeof(GWMSMM);k++)
{
tmp_offset += sizeof(GWMSMM);
if(strncmp(tmp_zjh,((struct GWMSMM*)(xx+k*sizeof(GWMSMM)))->zjh,strlen(tmp_zjh))!=0 )
continue;
mmoffset = tmp_offset-sizeof(GWMSMM);
memcpy(&mm,xx+k*sizeof(GWMSMM),sizeof(GWMSMM));
is=1;
break;
}
if(is)
break;
y = f_mm.Read(xx,array);
}
delete[] xx;
if(is==1)
{
struct GWMSMM ms_rec;
f_mm.Seek(mmoffset,CFile::begin);
memset(&ms_rec,'\0',sizeof(GWMSMM));
if(f_mm.Read(&ms_rec,sizeof(GWMSMM))!=sizeof(GWMSMM))
{
msg_put("Error _rtl_read when SETMM!!!");
f_mm.Close();
return -1;
}
ltoa(kg,ms_rec.f,10);
if(kg==0)
msg_put("修改为全开");
else if(kg==1)
msg_put("修改为无应答时进入秘书服务");
else
msg_put("取消秘书服");
f_mm.Seek(mmoffset,CFile::begin);
f_mm.Write(&ms_rec,sizeof(GWMSMM));
f_mm.Close();
}
else
{
struct GWMSMMW ms_rec;
memset(&ms_rec,'\0',sizeof(GWMSMMW));
ms_rec.start=0x20;
strncpy(ms_rec.zjh,zjhc,7);
ltoa(1234L,ms_rec.mm,10);
ltoa(kg,ms_rec.f,10);
if(kg==0)
msg_put("修改为全开");
else if(kg==1)
msg_put("修改为无应答时进入秘书服务");
else
msg_put("取消秘书服");
f_mm.Seek(xf_head.count*sizeof(GWMSMM)+xf_head.offset,CFile::begin);
f_mm.Write(&ms_rec,sizeof(GWMSMMW));
if(f_mm.Seek(4,CFile::begin)==-1)
{
msg_put("Lseek XF.dbf error when write_start_time!");
f_mm.Close();
return(4);
}
xf_head.count++;
f_mm.Write(&xf_head.count,4);
msg_put("设置密码完成");
}
f_mm.Close();
ret=1;
return ret;
}
void CTimeClientDlg::Ontj()
{
CTjfw cx;
int ret=cx.DoModal();
if(ret!=IDOK)
return;
k1=cx.m_yhname;
sprintf(k2,"%s",cx.m_fwname);
//建一个dbf库 存放,建个结构体
CFile handle;
DBF_HEAD dbfhead;
char ss[60];
FW *s;
wsprintf(ss,"d:\\lx\\dqdl.dbf");
if(!handle.Open(ss,CFile::modeReadWrite|CFile::shareDenyNone))
{
MessageBox("Cannot Open d:\\lx\\dqlx.dbf open error!");
return;
}
handle.Seek(0,CFile::begin);
handle.Read(&dbfhead,sizeof(DBF_HEAD));
long to=dbfhead.count;
s=new FW[to];
handle.Seek(dbfhead.offset,CFile::begin);
handle.Read(s,to*sizeof(FW));
int is=1;
for(long i=0;i<to;i++) //判断是否有重复
{
//如果重复
if(strncmp(cx.m_fwname,s[i].Diqu,sizeof(s[i].Diqu))==0)
{
MessageBox("已存在,请确定后输入!");
is=0;
break;
}
}
if(is==1)
{
for(long i=0;i<to;i++)
{
if(memcmp("0x20",s[i].Diqu,1) == 0)//空位置
{
FW c;
handle.Seek(i*sizeof(FW)+dbfhead.offset,CFile::begin);
c.mark=s[0].mark;
sprintf(c.Diqu,"%s",k2);
sprintf(c.yhnub,"%d",k1);
handle.Write(&c,to*sizeof(FW));
MessageBox("添加成功");
break;
}
}
if(i>=to)//没有空位置
{
FWZ c;
handle.Seek(dbfhead.offset+to*sizeof(FW),CFile::begin);
c.mark=0x20;
sprintf(c.Diqu,"%s",k2);
sprintf(c.yhnub,"%d",cx.m_yhname);
c.end_flag=0x1a;
handle.Write(&c,sizeof(FWZ));
dbfhead.count++;
handle.Seek(0,CFile::begin);
handle.Write(&dbfhead,sizeof(DBF_HEAD));
MessageBox("添加成功");
}
}
handle.Close();
return ;
}
void CTimeClientDlg::OnSc()
{
CSc cx;
int ret=cx.DoModal();
if(ret!=IDOK)
return;
CFile handle;
DBF_HEAD dbfhead;
char ss[60];
FW *s;
wsprintf(ss,"d:\\lx\\dqdl.dbf");
if(!handle.Open(ss,CFile::modeReadWrite|CFile::shareDenyNone))
{
MessageBox("Cannot Open d:\\lx\\dqdl.dbf open error!");
return;
}
handle.Seek(0,CFile::begin);
handle.Read(&dbfhead,sizeof(DBF_HEAD));
long to=dbfhead.count;
s=new FW[to];
handle.Seek(dbfhead.offset,CFile::begin);
handle.Read(s,to*sizeof(FW));
for(long i=0;i<to;i++)
{
if(strncmp(s[i].Diqu,cx.m_fw,sizeof(cx.m_fw))==0)
{
char ss[4];
sprintf(ss,"%d",cx.m_yh);
if(strncmp(s[i].yhnub,ss,sizeof(ss))==0)
{
FW c;
memset(&c,0x20,sizeof(FW));
for(long j=0;j<8;j++)
{
c.Diqu[j]=0x20;
}
for(long z=0;z<4;z++)
{
c.yhnub[z]=0x20;
}
handle.Seek(dbfhead.offset+i*sizeof(FW),CFile::begin);
handle.Write(&c,sizeof(FW));
handle.Close();
break;
MessageBox("删除成功");
}
}
}
}
bool CTimeClientDlg::PD(char *ss,char *clip) //ss 为传过来的内容
{
char s[10],sss[10];
for(int i=0; i<MAX_CLIENT; i++ )//加IP
{
str=m_listClient.GetItemText(i,3);
if(strncmp(ss,str,str.GetLength())==0) //判断是否相同 ——相同
{
sprintf(s,"%s",ss);
sprintf(sss,"%s","服务");
m_listClient.SetItemText( i, 1, clip );
m_listClient.SetItemText( i, 2, "Login" );//显IP
m_listClient.SetItemText( i, 3, s );
m_listClient.SetItemText( i, 4, sss );
break;
}
else
continue;
}
if(i>=MAX_CLIENT)//没有相同的
return true;
else
return false;
}
void CTimeClientDlg::Ddq(long qq,CTupSocket * pSocket,char *clip)
{
long m;
long is=0;
char cc[60];
char s[20];
char ss[20];
CString str1;
FW *c;
DBF_HEAD dbfhead;
wsprintf(cc,"d:\\lx\\dqdl.dbf");
if(!handle.Open(cc,CFile::modeReadWrite|CFile::shareDenyNone))
{
MessageBox("错误","d:\\lx\\dqdl.dbf");
return;
}
handle.Seek(0,CFile::begin);
handle.Read(&dbfhead,sizeof(DBF_HEAD));
long to=dbfhead.count;
c=new FW[to];
handle.Seek(dbfhead.offset,CFile::begin);
handle.Read(c,to*sizeof(FW));
handle.Close();
for(long j=0;j<to;j++)
{
char nn[10];
sprintf(nn,"%d",qq);
str3=nn;
if(strncmp(c[j].yhnub,str3.Left(2),2)!=0)//地区号相同 7位 ,c[j].yhnub 为两位
continue;
else
{
str1=c[j].Diqu;
break;
}
}
if(j>=to)
{
msg_put("非法用户");
msg_put(clip);
return;
}
for(int i=0; i<MAX_CLIENT; i++ )//在表格添加登陆者的信息
{
if( m_pzClientSocket[i]==pSocket )
{
sprintf(s,"%s","用户");
sprintf(ss,"%s",str1);
m_listClient.SetItemText( i, 1, clip );
m_listClient.SetItemText( i, 2, "Login" );//显IP
m_listClient.SetItemText( i, 3, s );
m_listClient.SetItemText( i, 4, ss );
m=i;
sprintf(msg,"%s<-用户","用户来的包");
msg_put(msg);
break;
}
}
for(long z=0;z<MAX_CLIENT;z++) // 发送登陆者对应的服务器的IP
{
d=m_listClient.GetItemText(z,3);
long mm;
if(d.GetLength()>=str1.GetLength())
mm=d.GetLength();
else
mm=str1.GetLength();
if(strncmp(str1,d,mm)==0) //相同
{
b=m_listClient.GetItemText(z,1);
if(m_pzClientSocket[m]!=NULL)
{
m_pzClientSocket[m]->Send((LPCTSTR)b, b.GetLength());
}
break;
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -