www.gusucode.com > 大学排课系统,VC++实现,能实现根据教师及课程资源自动排 > 大学排课系统,VC++实现,能实现根据教师及课程资源自动排课/ARRANGE/EmptyroomDlg.cpp
// EmptyroomDlg.cpp : implementation file // #include "stdafx.h" #include "arrange.h" #include "EmptyroomDlg.h" #include "Emptyroomset.h" #include "ClassRoomSet.h" #include "QueryclassroomSet.h" #include "WBButton.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CEmptyroomDlg dialog CEmptyroomDlg::CEmptyroomDlg(CWnd* pParent /*=NULL*/) : CDialog(CEmptyroomDlg::IDD, pParent) { //{{AFX_DATA_INIT(CEmptyroomDlg) m_timenew = _T(""); m_roomTypeSel = _T(""); m_Value1 = 0; m_Value2 = 0; m_Value3 = 0; //}}AFX_DATA_INIT } void CEmptyroomDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CEmptyroomDlg) DDX_Control(pDX, IDC_LISTEMPTY, m_listempty); DDX_CBString(pDX, IDC_COMBO1, m_timenew); DDX_CBString(pDX, IDC_COMBO4, m_roomTypeSel); DDX_Text(pDX, IDC_EDIT1, m_Value1); DDX_Text(pDX, IDC_EDIT2, m_Value2); DDX_Text(pDX, IDC_EDIT3, m_Value3); DDX_Control(pDX, IDOK, m_Ok); DDX_Control(pDX, IDC_note_click, m_look); DDX_Control(pDX, IDC_Bsearch, m_query); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CEmptyroomDlg, CDialog) //{{AFX_MSG_MAP(CEmptyroomDlg) ON_BN_CLICKED(IDC_Bsearch, OnBsearch) ON_BN_CLICKED(IDC_note_click, Onnoteclick) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEmptyroomDlg message handlers BOOL CEmptyroomDlg::OnInitDialog() { CDialog::OnInitDialog(); if (!m_database.IsOpen()) { m_database.Open(_T("stct")); } // TODO: Add extra initialization here m_listempty.InsertColumn(0, "序号"); m_listempty.InsertColumn(1, "教室名称"); m_listempty.InsertColumn(2, "教室大小"); m_listempty.InsertColumn(3, "是否有多媒体"); RECT rectclassroom; m_listempty.GetWindowRect(&rectclassroom); int width = rectclassroom.right - rectclassroom.left; m_listempty.SetColumnWidth(0, width/4); m_listempty.SetColumnWidth(1, width/4); m_listempty.SetColumnWidth(2, width/4); m_listempty.SetColumnWidth(3, width/4); m_listempty.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_TRACKSELECT); m_Ok.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 ); m_look.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 ); m_query.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 ); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CEmptyroomDlg::OnBsearch() { //查询各种空教室 // TODO: Add your control notification handler code here UpdateData(TRUE); if (!m_database.IsOpen()) { m_database.Open(_T("stct")); //打开数据库 } CClassRoomSet m_pCRSet(&m_database); CQueryclassroomSet m_pQCRSet(&m_database); CString p_query2; CString sTime1, capacity1,capacity2,capacity3,roomtype,strState,strChange; int iroomtype; int choice=CDialog::GetCheckedRadioButton(IDC_RADIO2,IDC_RADIO3); //定义选择控制变量 GetDlgItemText(IDC_COMBO4,roomtype); GetDlgItemText(IDC_COMBO1,sTime1); //得到各控件id if(roomtype =="有多媒体") iroomtype=1; else iroomtype=0; int temp; if(m_Value1 > m_Value2) { temp = m_Value1; m_Value1 = m_Value2; m_Value2=temp; } if(choice==IDC_RADIO2)//选择非精确匹配查询 { ((CButton*)GetDlgItem(IDC_RADIO3))->SetCheck(FALSE);//将精确匹配radio控件设为无效状态 if(sTime1== "本学期全部无课教室") { p_query2="delete from EMPTYROOM where room_id in (select room_id from EMPTYROOM)"; //清空以前纪录 m_database.ExecuteSQL(p_query2); p_query2.Format("INSERT INTO EMPTYROOM (room_id,room_size,room_type) SELECT room_id,room_size,room_type FROM CLASSROOMS WHERE room_id NOT IN (SELECT DISTINCT room_id FROM QUERYCLASSROOM) and room_size between %d and %d and room_type=%d",m_Value1,m_Value2,iroomtype); m_database.ExecuteSQL(p_query2); //在空表中插入符合sql语句要求的纪录 } else { p_query2="delete from EMPTYROOM where room_id in (select room_id from EMPTYROOM)";//清空以前纪录 m_database.ExecuteSQL(p_query2); p_query2.Format("INSERT INTO EMPTYROOM (room_id,room_size,room_type) SELECT room_id,room_size,room_type FROM CLASSROOMS WHERE room_id IN (SELECT DISTINCT room_id FROM QUERYCLASSROOM where ctime<>'%s') and room_size between %d and %d and room_type=%d ",sTime1,m_Value1,m_Value2,iroomtype); m_database.ExecuteSQL(p_query2); //在空表中插入符合sql语句要求的纪录 } } else if(choice==IDC_RADIO3) //选择精确匹配查询 { ((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(FALSE);//将非精确匹配radio控件设为无效状态 if(sTime1== "本学期全部无课教室") { p_query2="delete from EMPTYROOM where room_id in (select room_id from EMPTYROOM)"; m_database.ExecuteSQL(p_query2); p_query2.Format("INSERT INTO EMPTYROOM (room_id,room_size,room_type) SELECT room_id,room_size,room_type FROM CLASSROOMS WHERE room_id NOT IN (SELECT DISTINCT room_id FROM QUERYCLASSROOM) and room_size =%d and room_type=%d",m_Value3,iroomtype); m_database.ExecuteSQL(p_query2); UpdateData(TRUE); } else { p_query2="delete from EMPTYROOM where room_id in (select room_id from EMPTYROOM)"; m_database.ExecuteSQL(p_query2); p_query2.Format("INSERT INTO EMPTYROOM (room_id,room_size,room_type) SELECT room_id,room_size,room_type FROM CLASSROOMS WHERE room_id IN (SELECT DISTINCT room_id FROM QUERYCLASSROOM where ctime<>'%s') and room_size=%d and room_type=%d",sTime1,m_Value3,iroomtype); m_database.ExecuteSQL(p_query2); } } else { p_query2="delete from EMPTYROOM where room_id in (select room_id from EMPTYROOM)"; m_database.ExecuteSQL(p_query2); MessageBox("请选择查询条件!"); } emptyroomdisp(); //显示查询结果 } void CEmptyroomDlg::emptyroomdisp() { m_listempty.DeleteAllItems(); //清空原来已显示的内容 CEmptyroomset m_pERSet(&m_database); m_pERSet.Open(); CDBVariant varValue; if(m_pERSet.GetRecordCount()!=0) m_pERSet.MoveFirst(); else AfxMessageBox(_T("记录不存在!请重新输入!")); char buf[40]; //定义一个数组在显示记录时类型转换使用 int i=0; // 用来记录当前记录 while(!m_pERSet.IsEOF()) { int temp=0; sprintf(buf,"%d",i+1); //得到记录集第一列的域值 m_listempty.InsertItem(i,buf); //对记录的显示处理 m_pERSet.GetFieldValue(1,varValue); m_listempty.SetItemText(i,1,varValue.m_pstring->GetBuffer(1)); m_pERSet.GetFieldValue(2,varValue); sprintf(buf,"%d",varValue.m_iVal); m_listempty.SetItemText(i,2,buf); m_pERSet.GetFieldValue(3,varValue); sprintf(buf,"%d",varValue.m_iVal); m_listempty.SetItemText(i,3,buf); i++; m_pERSet.MoveNext(); } } void CEmptyroomDlg::Onnoteclick() { // TODO: Add your control notification handler code here MessageBox(" 因为我们发现在重大上自习找教室是一个很麻烦的事情,所以我们特编写这个,希望学校也能方便我们!","使用提示!"); } void CEmptyroomDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CBitmap m_bitmap; CDC memDC; memDC.CreateCompatibleDC(&dc); m_bitmap.LoadBitmap(IDB_BITMAP3); memDC.SelectObject(&m_bitmap); dc.BitBlt(0,0,900,900,&memDC,0,0,SRCCOPY); // Do not call CDialog::OnPaint() for painting messages }