⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgmain.cpp

📁 数据库服务
💻 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 + -