// ClsData.cpp : 实现文件
//
#include "stdafx.h"
#include "ScoreGather.h"
#include "ClsData.h"
#include ".\clsdata.h"
// CClsData 对话框
IMPLEMENT_DYNAMIC(CClsData, CDialog)
CClsData::CClsData(CWnd* pParent /*=NULL*/)
: CDialog(CClsData::IDD, pParent)
{
}
CClsData::~CClsData()
{
}
void CClsData::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_YEAR, m_year);
DDX_Control(pDX, IDC_SCHOOL, m_school);
DDX_Control(pDX, IDC_CLASS, m_class);
DDX_Control(pDX, IDC_COURSE, m_course);
DDX_Control(pDX, IDC_PROGRESS1, m_progress1);
DDX_Control(pDX, IDC_STARTCLS, m_startcls);
DDX_Control(pDX, ID_OK, m_ok);
DDX_Control(pDX, IDC_PLACENAME, m_placename);
}
BEGIN_MESSAGE_MAP(CClsData, CDialog)
ON_BN_CLICKED(IDC_STARTCLS, OnBnClickedStartcls)
ON_BN_CLICKED(ID_OK, OnBnClickedOk)
ON_EN_SETFOCUS(IDC_DATATEXT, OnEnSetfocusDatatext)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CClsData 消息处理程序
void CClsData::OnBnClickedStartcls()
{
CString string,del_year,del_place,del_school,del_class,del_course;
m_year.GetLBText(m_year.GetCurSel(),del_year);
m_placename.GetLBText(m_placename.GetCurSel(),del_place);
m_school.GetLBText(m_school.GetCurSel(),del_school);
m_class.GetLBText(m_class.GetCurSel(),del_class);
m_course.GetLBText(m_course.GetCurSel(),del_course);
if(del_year=="全部" && del_school=="全部" && del_place=="全部" && del_class=="全部" && del_course=="全部")
string="将要删除[数据库]中{-- 全部 --}数据;\r\n";
else
{
if(del_year=="全部")
string="将要删除[数据库]中{-- 全部 --}年度的数据;\r\n";
else
string="将要删除[数据库]中所有{-- "+del_year+" --}的数据;\r\n";
if(del_place=="全部")
string="将要删除[数据库]中{-- 全部 --}乡镇的数据;\r\n";
else
string="将要删除[数据库]中所有{-- "+del_place+" --}的数据;\r\n";
if(del_school=="全部")
string=string+"将要删除[数据库]中上述范围内{-- 全部 --}学校的数据;\r\n";
else
string=string+"将要删除[数据库]中上述范围内所有{-- "+del_school+" --}的数据;\r\n";
if(del_class=="全部")
string=string+"将要删除[数据库]中上述范围内{-- 全部 --}班级的数据;\r\n";
else
string=string+"将要删除[数据库]中上述范围内所有{-- "+del_class+" --}的数据;\r\n";
if(del_course=="全部")
string=string+"将要删除[数据库]中上述范围内{-- 全部 --}学科的数据;\r\n";
else
string=string+"将要删除[数据库]中上述范围内所有{-- "+del_course+" --}学科的数据;\r\n";
}
if(AfxMessageBox(string+"\r\n是否要删除?请确认!", MB_YESNO|MB_ICONWARNING)==IDYES)
{
m_progress1.SetRange(0,120);
m_progress1.SetStep(20);
if(del_year=="全部" && del_place=="全部" && del_school=="全部" && del_class=="全部" && del_course=="全部")
{
CString strSQL;
strSQL="delete from courseteacher";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
strSQL="delete from dataedit";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
strSQL="delete from formula";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
strSQL="delete from gatherpageset";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
strSQL="delete from schoolnumber";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
strSQL="delete from yearcourse";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
}
/*else
{
CString strSQL;
strSQL="delete from dataset";
int xy=0;
if(del_year!="全部")
{
strSQL=strSQL+" where my_year='"+del_year+"'";
xy=1;
}
if(del_school!="全部")
{
if(xy)
strSQL=strSQL+" and my_school='"+del_school+"'";
else
strSQL=strSQL+" where my_school='"+del_school+"'";
xy=1;
}
else
xy=0;
if(del_class!="全部")
{
if(xy)
strSQL=strSQL+" and my_class='"+del_class+"'";
else
strSQL=strSQL+" where my_class='"+del_class+"'";
xy=1;
}
else
xy=0;
if(del_course!="全部")
if(xy)
strSQL=strSQL+" and my_course='"+del_course+"'";
else
strSQL=strSQL+" where my_course='"+del_course+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
strSQL="delete from dataedit";
xy=0;
if(del_year!="全部")
{
strSQL=strSQL+" where my_year='"+del_year+"'";
xy=1;
}
if(del_school!="全部")
{
if(xy)
strSQL=strSQL+" and my_school='"+del_school+"'";
else
strSQL=strSQL+" where my_school='"+del_school+"'";
xy=1;
}
else
xy=0;
if(del_class!="全部")
{
if(xy)
strSQL=strSQL+" and my_class='"+del_class+"'";
else
strSQL=strSQL+" where my_class='"+del_class+"'";
xy=1;
}
else
xy=0;
if(del_course!="全部")
if(xy)
strSQL=strSQL+" and my_course='"+del_course+"'";
else
strSQL=strSQL+" where my_course='"+del_course+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
strSQL="delete from gatherpageset";
xy=0;
if(del_year!="全部")
{
strSQL=strSQL+" where my_year='"+del_year+"'";
xy=1;
}
if(del_school!="全部")
{
if(xy)
strSQL=strSQL+" and my_school='"+del_school+"'";
else
strSQL=strSQL+" where my_school='"+del_school+"'";
}
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_progress1.StepIt();
}*/
CDialog::OnOK();
}
}
void CClsData::OnBnClickedOk()
{
CDialog::OnCancel();
}
BOOL CClsData::OnInitDialog()
{
CDialog::OnInitDialog();
m_tooltip.Create(this,TTS_ALWAYSTIP);
m_tooltip.Activate(TRUE);
m_tooltip.AddTool(GetDlgItem(IDC_YEAR),IDS_YEAR);
m_tooltip.AddTool(GetDlgItem(IDC_PLACENAME),IDS_SCN_PLACENAME);
m_tooltip.AddTool(GetDlgItem(IDC_SCHOOL),IDS_SCHOOL);
m_tooltip.AddTool(GetDlgItem(IDC_CLASS),IDS_CLASS);
m_tooltip.AddTool(GetDlgItem(IDC_COURSE),IDS_COURSE);
m_tooltip.AddTool(GetDlgItem(IDC_DATATEXT),IDS_DATATEXT);
m_tooltip.AddTool(GetDlgItem(IDC_STARTCLS),IDS_START);
m_tooltip.AddTool(GetDlgItem(IDC_PROGRESS1),IDS_PROGRESS1);
m_tooltip.AddTool(GetDlgItem(ID_OK),IDS_CANCEL);
m_year.AddString("全部");
m_placename.AddString("全部");
m_school.AddString("全部");
m_class.AddString("全部");
m_course.AddString("全部");
CString strSQL;
strSQL="select * from yearcourse";
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CScoreGatherApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
CString str_field;
while(!(m_pRecordset->adoEOF))
{
str_field=p_MySetClass->GetString(m_pRecordset->GetCollect("my_year"));
if(m_year.FindString(0,str_field)==CB_ERR)
m_year.AddString(str_field);
str_field=p_MySetClass->GetString(m_pRecordset->GetCollect("my_coursename"));
if(m_course.FindString(0,str_field)==CB_ERR)
m_course.AddString(str_field);
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
m_pRecordset==NULL;
strSQL="select * from schoolnumber";
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CScoreGatherApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
CString str_field;
while(!(m_pRecordset->adoEOF))
{
str_field=p_MySetClass->GetString(m_pRecordset->GetCollect("my_placename"));
if(m_placename.FindString(0,str_field)==CB_ERR)
m_placename.AddString(str_field);
str_field=p_MySetClass->GetString(m_pRecordset->GetCollect("my_schoolname"));
if(m_school.FindString(0,str_field)==CB_ERR)
m_school.AddString(str_field);
str_field=p_MySetClass->GetString(m_pRecordset->GetCollect("my_gradeclassname"));
if(m_class.FindString(0,str_field)==CB_ERR)
m_class.AddString(str_field);
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
m_pRecordset==NULL;
m_year.SetCurSel(0);
m_placename.SetCurSel(0);
m_school.SetCurSel(0);
m_class.SetCurSel(0);
m_course.SetCurSel(0);
return TRUE;
}
void CClsData::OnEnSetfocusDatatext()
{
GotoDlgCtrl(GetDlgItem(IDC_STATIC));
}
BOOL CClsData::PreTranslateMessage(MSG* pMsg)
{
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
BOOL CClsData::OnEraseBkgnd(CDC* pDC)
{
CBrush brush(RGB(210,220,210));
CBrush* pOldBrush=pDC->SelectObject(&brush);
CRect rcClip;
pDC->GetClipBox(&rcClip);
pDC->PatBlt(rcClip.left,rcClip.top,rcClip.Width(),rcClip.Height(),PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}
HBRUSH CClsData::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(nCtlColor!=CTLCOLOR_EDIT)
{
pDC->SetTextColor(RGB(40,20,255));
pDC->SetBkMode(TRANSPARENT);
HBRUSH B = CreateSolidBrush(RGB(210,220,210));
return (HBRUSH) B;
}
else
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
void CClsData::OnCancel()
{
}
void CClsData::OnOK()
{
}