📄 flquerystu_infodlg.cpp
字号:
// flquerystu_infoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "pmz.h"
#include "pmzDlg.h"
#include "flquerystu_infoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// flquerystu_infoDlg dialog
flquerystu_infoDlg::flquerystu_infoDlg(CWnd* pParent /*=NULL*/)
: CPmzDlg(pParent)
{
//{{AFX_DATA_INIT(flquerystu_infoDlg)
m_sno = _T("");
m_dno = _T("");
m_sname = _T("");
m_splace = _T("");
m_sclass = _T("");
//}}AFX_DATA_INIT
m_pdb=new CDatabase; //yang
m_pdb->Open( NULL, FALSE, FALSE,mydb);
}
flquerystu_infoDlg::~flquerystu_infoDlg()
{
m_pdb->Close();
delete m_pdb;
}
flquerystu_infoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CListCtrl* m_pList = (CListCtrl*)GetDlgItem(IDC_LIST2);
DWORD dwStyle= GetWindowLong(m_pList->m_hWnd, GWL_STYLE);
SetWindowLong( m_pList->m_hWnd, GWL_STYLE, dwStyle | LVS_REPORT);
//设置ListCtrl可以整行选择和网格条纹
DWORD styles = m_pList->GetExtendedStyle();
m_pList->SetExtendedStyle(styles|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_pList->SetBkColor(RGB(0xFF, 0xFF, 0xE0));
m_pList->SetTextBkColor(RGB(0xFF, 0xFF, 0xE0));
//设置列的题头
m_pList->InsertColumn(1,"学号",LVCFMT_CENTER,80);
m_pList->InsertColumn(2,"姓名",LVCFMT_CENTER,120);
m_pList->InsertColumn(3,"性别",LVCFMT_CENTER,80);
m_pList->InsertColumn(4,"年龄",LVCFMT_CENTER,80);
m_pList->InsertColumn(5,"生源地",LVCFMT_CENTER,180);
m_pList->InsertColumn(6,"班级",LVCFMT_CENTER,180);
m_pList->InsertColumn(7,"所属院系",LVCFMT_CENTER,180);
m_ssex.AddString("男");
m_ssex.AddString("女");
m_ssex.SetCurSel(0);
return true;
}
void flquerystu_infoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(flquerystu_infoDlg)
DDX_Control(pDX, IDC_LIST2, m_pList);
DDX_Control(pDX, IDC_COMBO1, m_ssex);
DDX_Text(pDX, IDC_EDIT8, m_sno);
DDX_Text(pDX, IDC_EDIT2, m_dno);
DDX_Text(pDX, IDC_EDIT3, m_sname);
DDX_Text(pDX, IDC_EDIT4, m_splace);
DDX_Text(pDX, IDC_EDIT5, m_sclass);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(flquerystu_infoDlg, CDialog)
//{{AFX_MSG_MAP(flquerystu_infoDlg)
ON_BN_CLICKED(IDC_BUTTON1, Ondelete)
ON_WM_NCLBUTTONDOWN()
ON_WM_NCMOUSEMOVE()
ON_WM_SYSCOMMAND()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// flquerystu_infoDlg message handlers
void flquerystu_infoDlg::OnOK()
{
CListCtrl* m_pList = (CListCtrl*)GetDlgItem(IDC_LIST2);
m_pList->DeleteAllItems();
UpdateData(TRUE);
UINT nselect=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO6);
CString str1,str2,str3;
int index;
switch(nselect)
{
case IDC_RADIO1:
m_sno.TrimLeft();
m_sno.TrimRight();
if(m_sno.GetLength()<1)
{
AfxMessageBox("学生学号不能为空!");
return;
}
else
{
str1=m_sno;
str2="SELECT * FROM S_info where S_no='"+str1+"'";
}
break;
case IDC_RADIO2:
m_dno.TrimLeft();
m_dno.TrimRight();
if(m_dno.GetLength()<1)
{
AfxMessageBox("学生所在院系编号不能为空!");
return;
}
else
{
str1=m_dno;
str2="SELECT * FROM S_info where department_no='"+str1+"'";
}
break;
case IDC_RADIO3:
m_sname.TrimLeft();
m_sname.TrimRight();
if(m_sname.GetLength()<1)
{
AfxMessageBox("学生姓名不能为空!");
return;
}
else
{
str1=m_sname;
str2="SELECT * FROM S_info where S_name='"+str1+"'";
}
break;
case IDC_RADIO4:
index=m_ssex.GetCurSel();
m_ssex.GetLBText(index,str1);
if(str1=="")
{
AfxMessageBox("请选择性别!");
return;
}
else
{
str2="SELECT * FROM S_info where S_sex='"+str1+"'";
}
break;
case IDC_RADIO5:
m_splace.TrimLeft();
m_splace.TrimRight();
if(m_splace.GetLength()<1)
{
AfxMessageBox("学生地址不能为空!");
return;
}
else
{
str1=m_splace;
str2="SELECT * FROM S_info where S_place='"+str1+"'";
}
break;
case IDC_RADIO6:
m_sclass.TrimLeft();
m_sclass.TrimRight();
if(m_sclass.GetLength()<1)
{
AfxMessageBox("学生班级不能为空!");
return;
}
else
{
str1=m_sclass;
str2="SELECT * FROM S_info where S_class='"+str1+"'";
}
break;
}
CString s_no,s_name,s_sex,s_age,s_place,s_class,s_department_no,s_department;
m_pList->DeleteAllItems();
m_sprecordset=new S_infodb(m_pdb);
m_sprecordset->Open(S_infodb::snapshot,str2);
int i=0;
if(m_sprecordset->IsEOF())
{
}
else
{
m_sprecordset->MoveFirst();
while(!m_sprecordset->IsEOF())
{
s_no=m_sprecordset->m_S_no;
s_name=m_sprecordset->m_S_name;
s_sex=m_sprecordset->m_S_sex;
s_age=m_sprecordset->m_S_age;
s_place=m_sprecordset->m_S_place;
s_class=m_sprecordset->m_S_class;
s_department_no=m_sprecordset->m_department_no;
str3="SELECT * FROM department_info where department_no='"+s_department_no+"'";
m_dprecordset=new department_infodb(m_pdb);
m_dprecordset->Open(department_infodb::snapshot,str3);
s_department=m_dprecordset->m_department_name;
m_pList->InsertItem(i,s_no);
m_pList->SetItemText(i,1,s_name);
m_pList->SetItemText(i,2,s_sex);
m_pList->SetItemText(i,3,s_age);
m_pList->SetItemText(i,4,s_place);
m_pList->SetItemText(i,5,s_class);
m_pList->SetItemText(i,6,s_department);
m_sprecordset->MoveNext();
i++;
}
}
delete m_sprecordset;
}
void flquerystu_infoDlg::Ondelete()
{
int j;
j=m_pList.GetSelectionMark();
if(j<0)
{
AfxMessageBox("请在列表框点击选中要删除的记录!");
return;
}
else
{
CString str;
str=m_pList.GetItemText(j,0);
if(str=="")
{
AfxMessageBox("列表框没有记录!");
return;
}
if(AfxMessageBox("这将删除所有与此院系有关的信息,继续吗?",MB_YESNO)==IDYES)
{
CString str1="delete from S_info where S_no= '"+str+"'";
m_pdb->ExecuteSQL(str1);
m_pList.DeleteItem(j);
AfxMessageBox("删除成功!");
}
else return;
}
}
void flquerystu_infoDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
CPmzDlg::OnNcLButtonDown(nHitTest, point);
}
void flquerystu_infoDlg::OnNcMouseMove(UINT nHitTest, CPoint point)
{
CPmzDlg::OnNcMouseMove(nHitTest, point);
}
void flquerystu_infoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
CPmzDlg::OnSysCommand(nID, lParam);
}
void flquerystu_infoDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -