📄 myyearxiang.cpp
字号:
// MyYearXiang.cpp : 实现文件
//
#include "stdafx.h"
#include "ScoreGather.h"
#include "MyYearXiang.h"
#include ".\myyearxiang.h"
// CMyYearXiang 对话框
IMPLEMENT_DYNAMIC(CMyYearXiang, CDialog)
CMyYearXiang::CMyYearXiang(CWnd* pParent /*=NULL*/)
: CDialog(CMyYearXiang::IDD, pParent)
{
}
CMyYearXiang::~CMyYearXiang()
{
}
void CMyYearXiang::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_list1);
DDX_Control(pDX, IDC_YEAR1, m_year1);
DDX_Control(pDX, IDC_YEAR2, m_year2);
DDX_Control(pDX, IDC_YEAR3, m_year3);
DDX_Control(pDX, IDC_COURSENAME, m_coursename);
DDX_Control(pDX, IDC_ADD, m_add);
DDX_Control(pDX, IDC_MODIFY, m_modify);
DDX_Control(pDX, IDC_DEL, m_del);
}
BEGIN_MESSAGE_MAP(CMyYearXiang, CDialog)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
ON_CBN_CLOSEUP(IDC_YEAR1, OnCbnCloseupYear1)
ON_CBN_CLOSEUP(IDC_YEAR2, OnCbnCloseupYear2)
ON_BN_CLICKED(IDC_ADD, OnBnClickedAdd)
ON_BN_CLICKED(IDC_MODIFY, OnBnClickedModify)
ON_BN_CLICKED(IDC_DEL, OnBnClickedDel)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CMyYearXiang 消息处理程序
BOOL CMyYearXiang::OnInitDialog()
{
CDialog::OnInitDialog();
m_tooltip.Create(this,TTS_ALWAYSTIP);
m_tooltip.Activate(TRUE);
m_tooltip.AddTool(GetDlgItem(IDC_YEAR1),IDS_YEAR1);
m_tooltip.AddTool(GetDlgItem(IDC_YEAR2),IDS_YEAR2);
m_tooltip.AddTool(GetDlgItem(IDC_YEAR3),IDS_YEAR3);
m_tooltip.AddTool(GetDlgItem(IDC_COURSENAME),IDS_COURSENAME);
m_tooltip.AddTool(GetDlgItem(IDC_ADD),IDS_ADD);
m_tooltip.AddTool(GetDlgItem(IDC_MODIFY),IDS_MODIFY);
m_tooltip.AddTool(GetDlgItem(IDC_DEL),IDS_DEL);
m_tooltip.AddTool(GetDlgItem(IDC_LIST1),IDS_YC_LIST1);
wnd_year1=GetDlgItem(IDC_YEAR1);
wnd_year2=GetDlgItem(IDC_YEAR2);
wnd_year3=GetDlgItem(IDC_YEAR3);
wnd_coursename=GetDlgItem(IDC_COURSENAME);
DWORD style;
style=m_list1.GetExStyle(); //获取样式
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ; //设置样式
m_list1.SetExtendedStyle(style); //应用样式
m_list1.InsertColumn(0,"学 年 度",LVCFMT_LEFT,300);
m_list1.InsertColumn(1,"学 科",LVCFMT_LEFT,244);
for(int i=2005;i<=2055;i++)
{
CString string;
string.Format("%d",i);
m_year1.AddString(string);
}
for(int i=2006;i<=2056;i++)
{
CString string;
string.Format("%d",i);
m_year2.AddString(string);
}
m_year3.AddString("一");
m_year3.AddString("二");
return TRUE;
}
void CMyYearXiang::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
POSITION pos=m_list1.GetFirstSelectedItemPosition();
int row;
if(pos)
{
row=m_list1.GetNextSelectedItem(pos);
m_year1.SetCurSel(m_year1.FindString(0,m_list1.GetItemText(row,0).Mid(1,4)));
m_year2.SetCurSel(m_year2.FindString(0,m_list1.GetItemText(row,0).Mid(9,4)));
m_year3.SetCurSel(m_year3.FindString(0,m_list1.GetItemText(row,0).Mid(23,2)));
SetDlgItemText(IDC_COURSENAME,m_list1.GetItemText(row,1));
}
else
{
m_year1.SetCurSel(-1);
m_year2.SetCurSel(-1);
m_year3.SetCurSel(-1);
SetDlgItemText(IDC_COURSENAME,"");
}
*pResult = 0;
}
void CMyYearXiang::OnCbnCloseupYear1()
{
m_year2.SetCurSel(m_year1.GetCurSel());
}
void CMyYearXiang::OnCbnCloseupYear2()
{
m_year1.SetCurSel(m_year2.GetCurSel());
}
void CMyYearXiang::OnBnClickedAdd()
{
int year1,year2,year3;
CString str1,str2,str3,str4,year;
year1=m_year1.GetCurSel();
year2=m_year2.GetCurSel();
year3=m_year3.GetCurSel();
if(year1<0)
{
AfxMessageBox("必须选择[?年度]!");
GotoDlgCtrl(wnd_year1);
return;
}
else
m_year1.GetLBText(year1,str1);
if(year2<0)
{
AfxMessageBox("必须选择[?年度]!");
GotoDlgCtrl(wnd_year2);
return;
}
else
m_year2.GetLBText(year2,str2);
if(year3<0)
{
AfxMessageBox("必须选择[第?学期]!");
GotoDlgCtrl(wnd_year3);
return;
}
else
m_year3.GetLBText(year3,str3);
GetDlgItemText(IDC_COURSENAME,str4);
if(str4.IsEmpty())
{
AfxMessageBox("必须填写[学科名称]!");
GotoDlgCtrl(wnd_coursename);
return;
}
year="["+str1+"]至["+str2+"]学年度第<"+str3+">学期";//年度
int row=m_list1.GetItemCount();
for(int i=0;i<=row;i++)
{
if(m_list1.GetItemText(i,0)+m_list1.GetItemText(i,1)==year+str4)
{
AfxMessageBox("数据不能重复!");
return;
}
}
m_list1.InsertItem(row,NULL);
m_list1.SetItemText(row,0,year);
m_list1.SetItemText(row,1,str4);
m_pRecordset->AddNew();
m_pRecordset->PutCollect("my_year",_variant_t(m_list1.GetItemText(row,0)));
m_pRecordset->PutCollect("my_coursename",_variant_t(m_list1.GetItemText(row,1)));
m_pRecordset->Update();
GotoDlgCtrl(wnd_year1);
}
void CMyYearXiang::OnBnClickedModify()
{
POSITION pos=m_list1.GetFirstSelectedItemPosition();
int row;
if(pos)
row=m_list1.GetNextSelectedItem(pos);
else
{
AfxMessageBox("请单击要修改的内容!");
return;
}
int year1,year2,year3;
CString str1,str2,str3,str4,year;
year1=m_year1.GetCurSel();
year2=m_year2.GetCurSel();
year3=m_year3.GetCurSel();
if(year1<0)
{
AfxMessageBox("必须选择[?年度]!");
GotoDlgCtrl(wnd_year1);
return;
}
else
m_year1.GetLBText(year1,str1);
if(year2<0)
{
AfxMessageBox("必须选择[?年度]!");
GotoDlgCtrl(wnd_year2);
return;
}
else
m_year2.GetLBText(year2,str2);
if(year3<0)
{
AfxMessageBox("必须选择[第?学期]!");
GotoDlgCtrl(wnd_year3);
return;
}
else
m_year3.GetLBText(year3,str3);
GetDlgItemText(IDC_COURSENAME,str4);
if(str4.IsEmpty())
{
AfxMessageBox("必须填写[学科名称]!");
GotoDlgCtrl(wnd_coursename);
return;
}
year="["+str1+"]至["+str2+"]学年度第<"+str3+">学期";//年度
int row1=m_list1.GetItemCount();
for(int i=0;i<=row1;i++)
{
if(row!=i)
if(m_list1.GetItemText(i,0)+m_list1.GetItemText(i,1)==year+str4)
{
AfxMessageBox("数据不能重复!");
return;
}
}
str1=m_list1.GetItemText(row,0);
str2=m_list1.GetItemText(row,1);
m_list1.SetItemText(row,0,year);
m_list1.SetItemText(row,1,str4);
CString strSQL;
strSQL="update yearcourse set ";
strSQL=strSQL+"my_year='"+m_list1.GetItemText(row,0)+"',";
strSQL=strSQL+"my_coursename='"+m_list1.GetItemText(row,1)+"'";
strSQL=strSQL+" where my_year='";
strSQL=strSQL+str1+"'";
strSQL=strSQL+" AND my_coursename='";
strSQL=strSQL+str2+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="update courseteacher set ";
strSQL=strSQL+"my_year='"+m_list1.GetItemText(row,0)+"',";
strSQL=strSQL+"my_coursename='"+m_list1.GetItemText(row,1)+"'";
strSQL=strSQL+" where my_year='";
strSQL=strSQL+str1+"'";
strSQL=strSQL+" AND my_coursename='";
strSQL=strSQL+str2+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="update dataedit set ";
strSQL=strSQL+"my_year='"+m_list1.GetItemText(row,0)+"',";
strSQL=strSQL+"my_course='"+m_list1.GetItemText(row,1)+"'";
strSQL=strSQL+" where my_year='";
strSQL=strSQL+str1+"'";
strSQL=strSQL+" AND my_course='";
strSQL=strSQL+str2+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="update formula set ";
strSQL=strSQL+"my_year='"+m_list1.GetItemText(row,0)+"'";
strSQL=strSQL+" where my_year='";
strSQL=strSQL+str1+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="update gatherpageset set ";
strSQL=strSQL+"my_year='"+m_list1.GetItemText(row,0)+"'";
strSQL=strSQL+" where my_year='";
strSQL=strSQL+str1+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="update schoolnumber set ";
strSQL=strSQL+"my_year='"+m_list1.GetItemText(row,0)+"'";
strSQL=strSQL+" where my_year='";
strSQL=strSQL+str1+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
}
void CMyYearXiang::OnBnClickedDel()
{
POSITION pos=m_list1.GetFirstSelectedItemPosition();
int row;
if(pos)
row=m_list1.GetNextSelectedItem(pos);
else
{
AfxMessageBox("请单击要删除的内容!");
return;
}
if(AfxMessageBox("是否要删除?请确认!", MB_YESNO|MB_ICONWARNING)==IDYES)
{
CString strSQL;
strSQL="delete from yearcourse where my_year='";
strSQL=strSQL+m_list1.GetItemText(row,0)+"'";
strSQL=strSQL+" AND my_coursename='";
strSQL=strSQL+m_list1.GetItemText(row,1)+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="delete from courseteacher where my_year='";
strSQL=strSQL+m_list1.GetItemText(row,0)+"'";
strSQL=strSQL+" AND my_coursename='";
strSQL=strSQL+m_list1.GetItemText(row,1)+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="delete from dataedit where my_year='";
strSQL=strSQL+m_list1.GetItemText(row,0)+"'";
strSQL=strSQL+" AND my_course='";
strSQL=strSQL+m_list1.GetItemText(row,1)+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="delete from formula where my_year='";
strSQL=strSQL+m_list1.GetItemText(row,0)+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="delete from gatherpageset where my_year='";
strSQL=strSQL+m_list1.GetItemText(row,0)+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
strSQL="delete from schoolnumber where my_year='";
strSQL=strSQL+m_list1.GetItemText(row,0)+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_list1.DeleteItem(row);
}
}
void CMyYearXiang::OnBnClickedOk()
{
//OnOK();
}
void CMyYearXiang::OnBnClickedCancel()
{
//OnCancel();
}
void CMyYearXiang::UpDateView(void)
{
m_year1.SetCurSel(-1);
m_year2.SetCurSel(-1);
m_year3.SetCurSel(-1);
SetDlgItemText(IDC_COURSENAME,_T(""));
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);
int r=0;
m_list1.DeleteAllItems();
while(!(m_pRecordset->adoEOF))
{
m_list1.InsertItem(r,NULL);
m_list1.SetItemText(r,0,p_MySetClass->GetString(m_pRecordset->GetCollect("my_year")));
m_list1.SetItemText(r,1,p_MySetClass->GetString(m_pRecordset->GetCollect("my_coursename")));
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
r++;
}
}
}
BOOL CMyYearXiang::PreTranslateMessage(MSG* pMsg)
{
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
void CMyYearXiang::OnCancel()
{
}
void CMyYearXiang::OnOK()
{
}
BOOL CMyYearXiang::OnEraseBkgnd(CDC* pDC)
{
CBrush brush(RGB(250,220,250));
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 CMyYearXiang::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(nCtlColor!=CTLCOLOR_EDIT)
{
pDC->SetTextColor(RGB(40,20,255));
pDC->SetBkMode(TRANSPARENT);
HBRUSH B = CreateSolidBrush(RGB(250,220,250));
return (HBRUSH) B;
}
else
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -