📄 dmsdlg.cpp
字号:
// DMSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DMS.h"
#include "DMSDlg.h"
#include "Common.h"
#include ".\dmsdlg.h"
#define m_IniFile "./qqpackate.ini"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Global:
HMODULE hModule = NULL; //for动态库Module;
HANDLE recvThread = 0; //接受线程句柄
CRITICAL_SECTION dataCS; //访问数据包的关键区
DATA g_Data; //用于保存数据包
bool end = false; //接受线程结束标志
bool autoRep = false; //自动回复
int send = 0;
int recv = 0;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDMSDlg dialog
IMPLEMENT_DYNAMIC(CDMSDlg, CDialog);
CDMSDlg::CDMSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDMSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDMSDlg)
m_port = 0;
m_recvP = _T("");
m_sendP = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_fConnected = FALSE;
m_strSource = "";
}
CDMSDlg::~CDMSDlg()
{
// If there is an automation proxy for this dialog, set
// its back pointer to this dialog to NULL, so it knows
// the dialog has been deleted.
}
void CDMSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDMSDlg)
DDX_Text(pDX, IDC_EDIT_PORT, m_port);
DDX_Text(pDX, IDC_EDIT_RECVP, m_recvP);
DDX_Text(pDX, IDC_EDIT_SENDP, m_sendP);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDMSDlg, CDialog)
//{{AFX_MSG_MAP(CDMSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUT_INIT, OnButInit)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDMSDlg message handlers
BOOL CDMSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, TRUE); // Set small icon
//=======================================================
HRESULT hr1;
try
{
hr1 = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr1))
{
//火线连接数据库ip地址和用户名密码
// hr1 = m_pConnection->Open("driver={SQL Server};Server=####;DATABASE=####;UID=####;PWD=####","","",adModeUnknown); ///连接数据库
//49数据库连接
hr1 = m_pConnection->Open("driver={SQL Server};Server=####;DATABASE=####;UID=####;PWD=####","","",adModeUnknown); ///连接数据库
}
if(SUCCEEDED(hr1))
{
hr1=m_pCommand.CreateInstance("ADODB.Command");
}
if(SUCCEEDED(hr1))
{
m_pRecordset.CreateInstance("ADODB.Recordset");
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
//=======================================================
//设置端口号
m_port =12016;
return TRUE; // return TRUE unless you set the focus to a control
}
void CDMSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDMSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDMSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// Automation servers should not exit when a user closes the UI
// if a controller still holds on to one of its objects. These
// message handlers make sure that if the proxy is still in use,
// then the UI is hidden but the dialog remains around if it
// is dismissed.
void CDMSDlg::OnButInit()
{
// TODO: Add your control notification handler code here
hModule = LoadLibrary("SPServer.dll");
if(NULL == hModule)
{
::AfxMessageBox("LoadLibrary() failed");
return;
}
InitFunc * f = (InitFunc*)GetProcAddress(hModule, "VSPPCommInit");
if(NULL == f)
{
::AfxMessageBox("Call VSPPCommInit() failed");
return;
}
UpdateData(FALSE);
f(m_port, 1); ///call VSPPCommInit()
this->GetDlgItem(IDC_BUT_INIT)->EnableWindow(FALSE);
DWORD thrdid;
recvThread = CreateThread( NULL, 0, MyRecvProc, (void*)this, 0, &thrdid);
}
DWORD WINAPI MyRecvProc(void * param)
{
RecvMsgFunc * pfRecv = (RecvMsgFunc*)GetProcAddress(hModule, "VSPPReceiveMessage");
if(NULL == pfRecv)
return 0;
PACKET_HEAD & phhead = g_Data.pack_head;
while(!end)
{
pfRecv((unsigned char*)g_Data.IP, g_Data.port, phhead, g_Data.pack_body);
recv++;
ProcessData(param);
//Sleep(200) //?
}
return 0;
}
void ProcessData(void * pData)
{
_CommandPtr m_pCommand;
_RecordsetPtr m_pRecordset;
_ConnectionPtr m_pConnection;
HRESULT hr1;
try
{
hr1 = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr1))
{
//火线连接数据库ip地址和用户名密码
// hr1 = m_pConnection->Open("driver={SQL Server};Server=####;DATABASE=####;UID=####;PWD=####","","",adModeUnknown); ///连接数据库
//49数据库连接
hr1 = m_pConnection->Open("driver={SQL Server};Server=####;DATABASE=####;UID=####;PWD=####","","",adModeUnknown); ///连接数据库
}
if(SUCCEEDED(hr1))
{
hr1=m_pCommand.CreateInstance("ADODB.Command");
}
if(SUCCEEDED(hr1))
{
m_pRecordset.CreateInstance("ADODB.Recordset");
}
}
catch(_com_error e)
{
}
//EnterCriticalSection(&dataCS);
g_Data.body_len = strlen(g_Data.pack_body);
char * buf = new char[MAX_PACKET_LEN+1];
strcpy(buf, "");
PackCHECK( buf, &g_Data.pack_head);
strcat(buf, g_Data.pack_body);
strcat(buf, "");
CDMSDlg* pDlg = (CDMSDlg*)pData;
CString str;
str.Format("%d",recv);
pDlg->GetDlgItem(IDC_RECV)->SetWindowText(str);
pDlg->GetDlgItem(IDC_EDIT_RECVP)->SetWindowText(buf);
strcpy( (char*)g_Data.pack_head.SUBCOMMAND, "02");
strcpy(buf, "");
PackCHECK( buf, &g_Data.pack_head);
char ServerName[256] = "";
TrimChar((char*)g_Data.pack_head.SPID,' ');
TrimChar((char*)g_Data.pack_head.SERVERID,' ');
TrimChar((char*)g_Data.pack_head.OPERATEID,' ');
TrimChar((char*)g_Data.pack_body,' ');
CString pwdstr;
sprintf(ServerName,"%s%s%s",g_Data.pack_head.SPID,
g_Data.pack_head.SERVERID,
g_Data.pack_head.OPERATEID);
CString body = g_Data.pack_body;
CString bStr[64],s;
int n,i = 0;
while(body.Find("|",0) != -1 && i < 64)
{
n = body.Find("|",0);
bStr[i] = body.Left(n);
i++;
body.Delete(0,n+1);
}
bStr[i] = body;
char* Operate = (char*)g_Data.pack_head.OPERATEID;
_variant_t callid; //用户手机号
_variant_t path; //文件路径
_variant_t nCount; //文件总数
_variant_t userID; //注册用户ID号
CString command;
CString insertcommand;
_variant_t Affected(0L);
_bstr_t query;
_bstr_t Testquery;
//int nCount1;
int nCount2;
int NextSongId;
CString nCountNO;
CString strSongName;
char strNextSongId[50];
char * bufsend = new char[127];
switch(atoi(Operate))
{
case 10001:
try
{
NextSongId=atoi(bStr[3])+1;
sprintf(strNextSongId,"%d",NextSongId);
command="SELECT * FROM NEWMQJ where type1= '";
command+=bStr[1];
command+="' and type2= '";
command+=bStr[2];
command+="' and type3= '";
command+=strNextSongId;
command+="'";
query = command;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open(query,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
nCount2=m_pRecordset->GetRecordCount();
sprintf(g_Data.pack_body,"");
strcpy(bufsend, "");
if(nCount2!=0)
{
strcpy(bufsend, strNextSongId); //歌曲id
strcat(bufsend,"|");
//strcat(bufsend,bStr[1]); //歌曲的名称
strSongName = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name");//歌曲的名称
strcat(bufsend,strSongName); //歌曲的名称
sprintf(g_Data.pack_body,bufsend);
}
else
{
sprintf(g_Data.pack_body,"0");
}
}
catch(_com_error e)
{
}
break;
case 10002:
try
{
NextSongId=atoi(bStr[3])+1;
sprintf(strNextSongId,"%d",NextSongId);
command="SELECT * FROM NEWMQJ where type1= '";
command+=bStr[1];
command+="' and type2= '";
command+=bStr[2];
command+="' and type3= '";
command+=strNextSongId;
command+="'";
query = command;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open(query,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
nCount2=m_pRecordset->GetRecordCount();
sprintf(g_Data.pack_body,"");
strcpy(bufsend, "");
if(nCount2!=0)
{
strcpy(bufsend, strNextSongId); //歌曲id
strcat(bufsend,"|");
//strcat(bufsend,bStr[1]); //歌曲的名称
strSongName = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name");//歌曲的名称
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -