?? dlgmain.cpp
字號:
// DlgMain.cpp : implementation file
//
#include "stdafx.h"
#include "NServer.h"
#include "DlgMain.h"
#include "DlgUserMgt.h"
#include "DlgLogMgt.h"
#include "DlgFileMgt.h"
#include "DlgServerConfig.h"
#include "DlgRequest.h"
#include "LogRst.h"
#include "AllIndexRst.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgMain dialog
CDlgMain::CDlgMain(CWnd* pParent /*=NULL*/)
: CDialog(CDlgMain::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgMain)
//}}AFX_DATA_INIT
}
void CDlgMain::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgMain)
DDX_Control(pDX, IDC_LIST_MAIN, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgMain, CDialog)
//{{AFX_MSG_MAP(CDlgMain)
ON_BN_CLICKED(IDC_BTN_EXITMAIN, OnBtnExitmain)
ON_BN_CLICKED(IDC_BTN_FILEMGT, OnBtnFilemgt)
ON_BN_CLICKED(IDC_BTN_HISLOG, OnBtnHislog)
ON_BN_CLICKED(IDC_BTN_USERMGT, OnBtnUsermgt)
ON_BN_CLICKED(IDC_BTN_START, OnBtnStart)
ON_BN_CLICKED(IDC_BTN_CONFIG, OnBtnConfig)
ON_BN_CLICKED(IDC_BTN_REQUEST, OnBtnRequest)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgMain message handlers
void CDlgMain::OnBtnExitmain()
{
CDialog::OnCancel();
}
void CDlgMain::OnBtnFilemgt()
{
CDlgFileMgt dlg;
dlg.DoModal();
}
void CDlgMain::OnBtnHislog()
{
CDlgLogMgt dlg;
dlg.DoModal();
}
void CDlgMain::OnBtnUsermgt()
{
CDlgUserMgt dlg;
dlg.DoModal();
}
void CDlgMain::OnBtnStart()
{
if(((CNServerApp *)AfxGetApp())->m_ServerPort<=0 || strlen(((CNServerApp *)AfxGetApp())->m_ServerIP)<=0){
((CNServerApp *)AfxGetApp())->AddLog("","","啟動服務器失敗,參數未設置");
MessageBox("請設置服務器參數!");
return;
}
if(!((CNServerApp *)AfxGetApp())->m_IsStart && ((CNServerApp *)AfxGetApp())->m_pListen == NULL){
((CNServerApp *)AfxGetApp())->m_pListen=new CListening();
if(((CNServerApp *)AfxGetApp())->m_pListen->Create(((CNServerApp *)AfxGetApp())->m_ServerPort))
{
((CNServerApp *)AfxGetApp())->AddLog("","","啟動服務器");
if(((CNServerApp *)AfxGetApp())->m_pListen->Listen())
{
((CNServerApp *)AfxGetApp())->m_IsStart = true;
GetDlgItem(IDC_BTN_START)->SetWindowText("停止服務");
return ;
}
else
{
((CNServerApp *)AfxGetApp())->AddLog("","","啟動服務器失敗,不能偵聽");
AfxMessageBox("Cannot listen!");
}
}
else
{
((CNServerApp *)AfxGetApp())->AddLog("","","啟動服務器失敗,不能創建socket");
AfxMessageBox("Cannot create socket!");
}
}
else{
if(((CNServerApp *)AfxGetApp())->m_pListen != NULL){
((CNServerApp *)AfxGetApp())->m_pListen->Close();
((CNServerApp *)AfxGetApp())->m_pListen = NULL;
}
((CNServerApp *)AfxGetApp())->AddLog("","","停止服務器");
((CNServerApp *)AfxGetApp())->DeleteClient();
((CNServerApp *)AfxGetApp())->m_IsStart = false;
GetDlgItem(IDC_BTN_START)->SetWindowText("啟動服務");
}
}
void CDlgMain::OnBtnConfig()
{
CDlgServerConfig m_config;
m_config.DoModal();
}
BOOL CDlgMain::OnInitDialog()
{
CDialog::OnInitDialog();
m_list.ModifyStyle(0, LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SINGLESEL);
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);
m_list.InsertColumn(0,"編號", LVCFMT_LEFT,70);
m_list.InsertColumn(1,"日期", LVCFMT_LEFT,200);
m_list.InsertColumn(2,"用戶編號", LVCFMT_LEFT,70);
m_list.InsertColumn(3,"用戶名稱", LVCFMT_LEFT,100);
m_list.InsertColumn(4,"內容", LVCFMT_LEFT,300);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgMain::OnBtnRequest()
{
CDlgRequest m_request;
m_request.DoModal();
}
void CDlgMain::AddLog(CString ComeCode,CString ComeName,CString LogCont)
{
CTime tm = CTime::GetCurrentTime();
CString strTM = "";
int nIndex = 0;
strTM.Format("%04d-%02d-%02d %02d:%02d:%02d",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond());
try{
CAllIndexRst dIndex;
if(dIndex.IsOpen())
dIndex.Close();
dIndex.m_strFilter = "IndexType = 101";
dIndex.Open();
if(!dIndex.IsEOF()){
nIndex = dIndex.m_IndexValue + 1;
dIndex.Edit();
dIndex.m_IndexValue = nIndex;
dIndex.Update();
}
else{
nIndex = 100;
dIndex.AddNew();
dIndex.m_IndexValue = nIndex;
dIndex.Update();
}
dIndex.Close();
if(nIndex <= 0 )
return;
CLogRst dLog;
if(dLog.IsOpen())
dLog.Close();
dLog.m_strFilter = "1 = 0";
dLog.Open();
dLog.AddNew();
dLog.m_LogIndex = nIndex;
dLog.m_LogTime = strTM;
if(strlen(ComeCode) <= 0)
dLog.m_ComeUserCode = 0;
else
dLog.m_ComeUserCode = atoi(ComeCode);
dLog.m_ComeUserName = ComeName;
dLog.m_LogContent = LogCont;
dLog.Update();
dLog.Close();
}
catch(...){;}
CString tempstr = "";
tempstr.Format("%d" , nIndex);
int nItem = this->m_list.InsertItem(0,tempstr);
this->m_list.SetItemText(nItem,1,strTM);
this->m_list.SetItemText(nItem,2,ComeCode);
this->m_list.SetItemText(nItem,3,ComeName);
this->m_list.SetItemText(nItem,4,LogCont);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -