📄 mywritegatherpage.cpp
字号:
m_list.SetItemText(r,3,p_MySetClass->GetString(m_pRecordset->GetCollect("my_gatheredit")));
r++;
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
m_pRecordset=NULL;
}
return TRUE;
}
void CMyWriteGatherPage::OnNMClickList(NMHDR *pNMHDR, LRESULT *pResult)
{
POSITION pos=m_list.GetFirstSelectedItemPosition();
int row;
if(pos)
{
m_placename.ResetContent();
m_schoolname.ResetContent();
row=m_list.GetNextSelectedItem(pos);
CString string1,string2,string3,string4;
string1=m_list.GetItemText(row,0);
string2=m_list.GetItemText(row,1);
string3=m_list.GetItemText(row,2);
string4=m_list.GetItemText(row,3);
m_year.SetCurSel(m_year.FindString(0,string1));
OnCbnSelchangeYear();
m_placename.SetCurSel(m_placename.FindString(0,string2));
OnCbnSelchangePlacename();
m_schoolname.SetCurSel(m_schoolname.FindString(0,string3));
SetDlgItemText(IDC_GATHERPAGEEDIT,string4);
}
else
{
m_year.SetCurSel(-1);
m_placename.SetCurSel(-1);
m_schoolname.SetCurSel(-1);
SetDlgItemText(IDC_GATHERPAGEEDIT,"");
}
*pResult = 0;
}
void CMyWriteGatherPage::OnBnClickedModify()
{
POSITION pos=m_list.GetFirstSelectedItemPosition();
int row;
if(pos)
row=m_list.GetNextSelectedItem(pos);
else
{
AfxMessageBox("请单击要修改的内容!");
return;
}
CString str_year,str_placename,str_schoolname,str_gatherpageedit,str_col0,str_col1,str_col2,str_col3;
str_col0=m_list.GetItemText(row,0);
str_col1=m_list.GetItemText(row,1);
str_col2=m_list.GetItemText(row,2);
str_col3=m_list.GetItemText(row,3);
int year,placename,schoolname;
year=placename=schoolname=-1;
placename=m_placename.GetCurSel();
year=m_year.GetCurSel();
schoolname=m_schoolname.GetCurSel();
if(year<0)
{
AfxMessageBox("[学年度]必须选择!");
GotoDlgCtrl(cwnd_year);
return;
}
else
m_year.GetLBText(year,str_year);
if(placename<0)
{
AfxMessageBox("[乡镇名称]必须选择!");
GotoDlgCtrl(cwnd_placename);
return;
}
else
m_placename.GetLBText(placename,str_placename);
if(schoolname<0)
{
AfxMessageBox("[学校名称]必须选择!");
GotoDlgCtrl(cwnd_schoolname);
return;
}
else
m_schoolname.GetLBText(schoolname,str_schoolname);
GetDlgItemText(IDC_GATHERPAGEEDIT,str_gatherpageedit);
if(str_gatherpageedit.IsEmpty())
{
AfxMessageBox("[成绩单函头]必须填写!");
GotoDlgCtrl(cwnd_gatherpageedit);
return;
}
int row1=m_list.GetItemCount();
for(int i=0;i<=row1;i++)
{
if(i!=row)
{
if(m_list.GetItemText(i,0)+m_list.GetItemText(i,1)+m_list.GetItemText(i,2)==str_year+str_placename+str_schoolname)
{
AfxMessageBox("数据不能重复!");
return;
}
}
}
CString strSQL;
strSQL="update gatherpageset set ";
strSQL=strSQL+"my_year='"+str_year+"',";
strSQL=strSQL+"my_place='"+str_placename+"',";
strSQL=strSQL+"my_school='"+str_schoolname+"',";
strSQL=strSQL+"my_gatheredit='"+str_gatherpageedit+"'";
strSQL=strSQL+" where my_year='";
strSQL=strSQL+str_col0+"'";
strSQL=strSQL+" AND my_place='";
strSQL=strSQL+str_col1+"'";
strSQL=strSQL+" AND my_school='";
strSQL=strSQL+str_col2+"'";
strSQL=strSQL+" AND my_gatheredit='";
strSQL=strSQL+str_col3+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_list.SetItemText(row,0,str_year);
m_list.SetItemText(row,1,str_placename);
m_list.SetItemText(row,2,str_schoolname);
m_list.SetItemText(row,3,str_gatherpageedit);
GotoDlgCtrl(cwnd_schoolname);
}
void CMyWriteGatherPage::OnBnClickedDel()
{
POSITION pos=m_list.GetFirstSelectedItemPosition();
int row;
if(pos)
row=m_list.GetNextSelectedItem(pos);
else
{
AfxMessageBox("请单击要修改的内容!");
return;
}
if(AfxMessageBox("是否要删除?请确认!", MB_YESNO|MB_ICONWARNING)==IDYES)
{
CString strSQL="delete from gatherpageset where my_year='";
strSQL=strSQL+m_list.GetItemText(row,0)+"'";
strSQL=strSQL+" AND my_place='";
strSQL=strSQL+m_list.GetItemText(row,1)+"'";
strSQL=strSQL+" AND my_school='";
strSQL=strSQL+m_list.GetItemText(row,2)+"'";
(((CScoreGatherApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
m_list.DeleteItem(row);
m_year.SetCurSel(-1);
m_placename.SetCurSel(-1);
m_schoolname.SetCurSel(-1);
SetDlgItemText(IDC_GATHERPAGEEDIT,"");
}
}
void CMyWriteGatherPage::OnCbnSelchangeYear()
{
if(m_year.GetCurSel()>=0)
{
m_placename.ResetContent();
m_schoolname.ResetContent();
SetDlgItemText(IDC_GATHERPAGEEDIT,_T(""));
CString str_year,strSQL;
m_year.GetLBText(m_year.GetCurSel(),str_year);
strSQL="select my_placename from schoolnumber where my_year='"+str_year+"'";
HRESULT hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()),
((CScoreGatherApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
CString str_field=p_MySetClass->GetString(m_pRecordset->GetCollect("my_placename"));
if(m_placename.FindString(0,str_field)==-1)
m_placename.AddString(str_field);
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
}
void CMyWriteGatherPage::OnCbnSelchangePlacename()
{
if(m_year.GetCurSel()>=0 && m_placename.GetCurSel()>=0)
{
m_schoolname.ResetContent();
SetDlgItemText(IDC_GATHERPAGEEDIT,_T(""));
CString str_year,str_place,strSQL;
m_year.GetLBText(m_year.GetCurSel(),str_year);
m_placename.GetLBText(m_placename.GetCurSel(),str_place);
strSQL="select my_schoolname from schoolnumber where my_year='"+str_year+"'"+" AND my_placename='"+str_place+"'";
HRESULT hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()),
((CScoreGatherApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
CString str_field=p_MySetClass->GetString(m_pRecordset->GetCollect("my_schoolname"));
if(m_schoolname.FindString(0,str_field)==-1)
m_schoolname.AddString(str_field);
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
}
BOOL CMyWriteGatherPage::PreTranslateMessage(MSG* pMsg)
{
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
BOOL CMyWriteGatherPage::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 CMyWriteGatherPage::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);
}
void CMyWriteGatherPage::OnCancel()
{
}
void CMyWriteGatherPage::OnOK()
{
}
void CMyWriteGatherPage::OnBnClickedCancel()
{
CDialog::OnCancel();
}
void CMyWriteGatherPage::OnBnClickedNewview()
{
m_schoolname.ResetContent();
SetDlgItemText(IDC_GATHERPAGEEDIT,_T(""));
m_list.DeleteAllItems();
CString strSQL="select * from gatherpageset";
HRESULT 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;
while(!(m_pRecordset->adoEOF))
{
m_list.InsertItem(r,NULL);
m_list.SetItemText(r,0,p_MySetClass->GetString(m_pRecordset->GetCollect("my_year")));
m_list.SetItemText(r,1,p_MySetClass->GetString(m_pRecordset->GetCollect("my_school")));
m_list.SetItemText(r,2,p_MySetClass->GetString(m_pRecordset->GetCollect("my_gatheredit")));
r++;
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
m_pRecordset=NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -