📄 netstrategydlg.cpp
字号:
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("初始化失败!","错误");
}
if(m_radioflag1==2)
{
EanbleControls();
if(m_radioflag2==1)
{
GetDlgItem(IDC_LIST1)->EnableWindow(TRUE);
GetDlgItem(IDC_LIST2)->EnableWindow(FALSE);
}
if(m_radioflag2==2)
{
GetDlgItem(IDC_LIST1)->EnableWindow(FALSE);
GetDlgItem(IDC_LIST2)->EnableWindow(TRUE);
}
}
else
DisableControls();
UpdateData(FALSE);
}
void CNetStrategyDlg::OnTimemonitorbtn()
{
// TODO: Add your control notification handler code here
//打开监控时间设置对话框
CTimeLimitSetDlg dlg;
dlg.DoModal();
}
BOOL CNetStrategyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//获得设备
CLeftTreeView *p_TreeView;
CSjsysDoc *m_pDoc=(CSjsysDoc *)((CMainFrame *)
AfxGetApp()->m_pMainWnd)->GetActiveDocument();
POSITION pos=m_pDoc->GetFirstViewPosition();
while (pos!=NULL)
{
CView *pView= m_pDoc->GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CLeftTreeView)))
p_TreeView=(CLeftTreeView *)pView;
}
CTreeCtrl &p_TreeCtrl=p_TreeView->GetTreeCtrl();
HTREEITEM item=p_TreeCtrl.GetSelectedItem();
m_getdevice=p_TreeCtrl.GetItemText(item);
CString SQLStr;
SQLStr.Format("select * from Device where Devicename='%s'",m_getdevice);
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)SQLStr.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
if (!m_pRecordset->adoEOF)
{
// m_deviceid=(char*)(_bstr_t)(_variant_t)m_pRecordset->GetCollect("ID");
m_deviceid=m_pRecordset->GetCollect("ID").lVal;
}
else
{
MessageBox("请先选择设备或选择设备错误");
CDialog::OnOK();
}
m_strdeviceid.Format("%d",m_deviceid);
m_pRecordset->Close();
//初始化按钮
m_savebtn.SetShade(CShadeButtonST::SHS_METAL);
m_timebtn.SetShade(CShadeButtonST::SHS_DIAGSHADE);
m_otherbtn.SetShade(CShadeButtonST::SHS_METAL);
m_downloadbtn.SetShade(CShadeButtonST::SHS_DIAGSHADE);
m_netbtn.SetShade(CShadeButtonST::SHS_METAL);
m_portbtn.SetShade(CShadeButtonST::SHS_DIAGSHADE);
m_mailbtn.SetShade(CShadeButtonST::SHS_DIAGSHADE);
m_timebtn.SetFlat(FALSE);
m_otherbtn.SetFlat(FALSE);
m_downloadbtn.SetFlat(FALSE);
m_netbtn.SetFlat(FALSE);
m_mailbtn.SetFlat(FALSE);
m_portbtn.SetFlat(FALSE);
m_savebtn.SetIcon(IDI_ICON5);
//m_savebtn.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(100,155,100));
// m_savebtn.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(0,155,155));
//m_radio2.SubclassDlgItem(IDC_RADIO2,this);
//m_radio2.SetIcon(IDI_ICON12,IDI_ICON13);
//初始化列表框
RECT rect1,rect2;
m_list11.GetWindowRect(&rect1);
int width1=rect1.right-rect1.left;
m_list22.GetWindowRect(&rect2);
int width2=rect2.right-rect2.left;
m_list11.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES|LVS_EDITLABELS);
m_list22.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES|LVS_EDITLABELS);
m_list11.InsertColumn(0," 网址",LVCFMT_CENTER,width1);
m_list22.InsertColumn(0," 网址",LVCFMT_CENTER,width2);
GetDlgItem(IDC_SENDSTATIC)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_RECEIVESTATIC)->ShowWindow(SW_HIDE);
//获取数据库中设备值
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
SQLStr.Format("select * from Urlfilter where Deviceid='%d'",m_deviceid);
m_pRecordset->Open((LPTSTR)SQLStr.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
int i=0;
int action=-1;
while(!(m_pRecordset->adoEOF))
{
action=m_pRecordset->GetCollect("Action").lVal;
if(action==1)
m_list11.InsertItem(i,((CSjsysApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Urlname")));
if(action==0)
m_list22.InsertItem(i,((CSjsysApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Urlname")));//
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("初始化失败!","错误");
}
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
SQLStr.Format("select * from filterconf where Deviceid='%d'",m_deviceid);
m_pRecordset->Open((LPTSTR)SQLStr.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
int i=0;
if(!(m_pRecordset->adoEOF))
{
m_radioflag1=m_pRecordset->GetCollect("bUrlMonitor").lVal;
m_radioflag2=m_pRecordset->GetCollect("bUsingUrlFilter").lVal;
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("初始化失败!","错误");
}
GetDlgItem(IDC_LIST3)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_LIST4)->ShowWindow(SW_HIDE);
if(m_radioflag1==2)
{
EanbleControls();
if(m_radioflag2==1)
GetDlgItem(IDC_LIST1)->EnableWindow(TRUE);
if(m_radioflag2==2)
GetDlgItem(IDC_LIST2)->EnableWindow(TRUE);
}
else
DisableControls();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CNetStrategyDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString s;
GetDlgItemText(IDC_RADIO4,s);
if(s=="所有文件类型"||s=="所有服务"||s=="所有端口")
return;
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem == -1)
{
m_list11.InsertItem(m_list11.GetItemCount(),"");
}
*pResult = 0;
}
void CNetStrategyDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString s;
GetDlgItemText(IDC_RADIO4,s);
if(s=="所有文件类型"||s=="所有服务"||s=="所有端口")
return;
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem == -1)
{
m_list22.InsertItem(m_list22.GetItemCount(),"");
}
*pResult = 0;
}
void CNetStrategyDlg::OnEndlabeleditList1(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
CString s;
GetDlgItemText(IDC_RADIO4,s);
if(s=="所有文件类型"||s=="所有服务"||s=="所有端口")
{
*pResult = 0;
return;
}
if(pDispInfo->item.pszText!=NULL)//判断是否已经取消取消编辑
m_list11.SetItemText(pDispInfo->item.iItem,0,pDispInfo->item.pszText);//重置显示字符
*pResult = 0;
}
void CNetStrategyDlg::OnEndlabeleditList2(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
CString s;
GetDlgItemText(IDC_RADIO4,s);
if(s=="所有文件类型"||s=="所有服务"||s=="所有端口")
{
*pResult = 0;
return;
}
if(pDispInfo->item.pszText!=NULL)//判断是否已经取消取消编辑
m_list22.SetItemText(pDispInfo->item.iItem,0,pDispInfo->item.pszText);//重置显示字符
*pResult = 0;
}
void CNetStrategyDlg::OnOk()
{
// TODO: Add your control notification handler code here
UpdateData();
int n=0;
int i=0;
CString SQLStr="";
_variant_t RecordsAffected;
switch(m_btnflag)
{
case 1:
m_flagstate[0]=m_radioflag1;
if(m_radioflag1==2)
{
GetControlInfo();
}
break;
case 2:
m_flagstate[2]=m_radioflag1;
if(m_radioflag1==2)
{
//m_flagstate[3]=m_radioflag2;
GetControlInfo();
}
break;
case 3:
m_flagstate[4]=m_radioflag1;
if(m_radioflag1==2)
{
//m_flagstate[5]=m_radioflag2;
GetControlInfo();
}
break;
case 4:
m_flagstate[6]=m_radioflag1;
if(m_radioflag1==2)
{
// m_flagstate[7]=m_radioflag2;
GetControlInfo();
}
break;
case 5:
m_flagstate[8]=m_radioflag1;
if(m_radioflag1==2)
{
// m_flagstate[9]=m_radioflag2;
GetControlInfo();
}
break;
default:
break;
}
if(IDYES==MessageBox("确定保存更改?", "询问",MB_YESNO|MB_ICONQUESTION))
{
if(m_flagstate[1]==1 && m_url[0].GetSize())
{
SQLStr.Format("delete from Urlfilter where Deviceid='%d' and Action='1'",m_deviceid);
(((CSjsysApp*)AfxGetApp())->pConnection)->Execute((_bstr_t)SQLStr,&RecordsAffected,adCmdText);
try
{
SQLStr="select * from Urlfilter";
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)SQLStr.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
for(int i=0;i<m_url[0].GetSize();i++)
{
m_pRecordset->AddNew();//添加新的记录
m_pRecordset->PutCollect("Deviceid",_variant_t(m_strdeviceid));
m_pRecordset->PutCollect("Urlname",_variant_t(m_url[0].GetAt(i)));
m_pRecordset->PutCollect("Action",_variant_t("1"));
m_pRecordset->Update(); //更新数据库
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
m_pRecordset->Close();
}
if(m_flagstate[1]==2 && m_url[1].GetSize())
{
SQLStr.Format("delete from Urlfilter where Deviceid='%d' and Action='0'",m_deviceid);
(((CSjsysApp*)AfxGetApp())->pConnection)->Execute((_bstr_t)SQLStr,&RecordsAffected,adCmdText);
try
{
SQLStr="select * from Urlfilter";
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)SQLStr.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
for(int i=0;i<m_url[1].GetSize();i++)
{
m_pRecordset->AddNew();//添加新的记录
m_pRecordset->PutCollect("Deviceid",_variant_t(m_strdeviceid));
m_pRecordset->PutCollect("Urlname",_variant_t(m_url[1].GetAt(i)));
m_pRecordset->PutCollect("Action",_variant_t("0"));
m_pRecordset->Update(); //更新数据库
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
m_pRecordset->Close();
}
if(m_flagstate[3]==1 && m_email[0].GetSize())
{
SQLStr.Format("delete from Emailfilter where Deviceid='%d'",m_deviceid);
(((CSjsysApp*)AfxGetApp())->pConnection)->Execute((_bstr_t)SQLStr,&RecordsAffected,adCmdText);
try
{
SQLStr="select * from Emailfilter";
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)SQLStr.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
for(int i=0;i<m_email[0].GetSize();i++)
{
m_pRecordset->AddNew();//添加新的记录
m_pRecordset->PutCollect("Deviceid",_variant_t(m_strdeviceid));
m_pRecordset->PutCollect("Sendemail",_variant_t(m_email[0].GetAt(i)));
m_pRecordset->PutCollect("Recevmail",_variant_t(m_email[1].GetAt(i)));
m_pRecordset->Update(); //更新数据库
}
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
m_pRecordset->Close();
}
if(m_flagstate[5]==1)
{
SQLStr.Format("delete from Ftpfilter where Deviceid='%d' and Action='1'",m_deviceid);
(((CSjsysApp*)AfxGetApp())->pConnection)->Execute((_bstr_t)SQLStr,&RecordsAffected,adCmdText);
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -