⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addkechengxinxidlg.cpp

📁 是我大学事情开发的一个很经典的案例
💻 CPP
字号:
// addkechengxinxiDlg.cpp : implementation file
//
//#include "string.h"
#include "stdafx.h"
#include "pmz.h"
#include "addkechengxinxiDlg.h"
#include "pmzDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// addkechengxinxiDlg dialog


addkechengxinxiDlg::addkechengxinxiDlg(CWnd* pParent /*=NULL*/)
	: CDialog(addkechengxinxiDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(addkechengxinxiDlg)
	m_cno = _T("");
	m_cname = _T("");
	m_cteacher_no = _T("");
	//}}AFX_DATA_INIT
	m_pdb=new CDatabase;          
	m_pdb->Open( NULL, FALSE, FALSE,mydb);
}
addkechengxinxiDlg::~addkechengxinxiDlg()
{m_pdb->Close();
delete m_pdb;
}

void addkechengxinxiDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(addkechengxinxiDlg)
	DDX_Control(pDX, IDC_COMBO4, m_jiaoshi);
	DDX_Control(pDX, IDC_COMBO3, m_jiaoxuelu);
	DDX_Control(pDX, IDC_COMBO2, m_jieshu);
	DDX_Control(pDX, IDC_COMBO1, m_xingqi);
	DDX_Text(pDX, IDC_EDIT1, m_cno);
	DDX_Text(pDX, IDC_EDIT2, m_cname);
	DDX_Text(pDX, IDC_EDIT5, m_cteacher_no);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(addkechengxinxiDlg, CDialog)
	//{{AFX_MSG_MAP(addkechengxinxiDlg)
	ON_BN_CLICKED(IDOK, Onaddkechengxinxi)
	ON_WM_PAINT()
	ON_CBN_KILLFOCUS(IDC_COMBO1, OnKillfocusCombo1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// addkechengxinxiDlg message handlers
BOOL addkechengxinxiDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
    
	m_xingqi.AddString("星期一");
	m_xingqi.AddString("星期二");
	m_xingqi.AddString("星期三");
	m_xingqi.AddString("星期四");
	m_xingqi.AddString("星期五");
	m_xingqi.AddString("星期六");
	m_xingqi.AddString("星期日");
	//m_xingqi.SetCurSel(0);
	

	m_jieshu.AddString("1,2");
	m_jieshu.AddString("3,4");
	m_jieshu.AddString("5,6");
	m_jieshu.AddString("7,8");
	m_jieshu.AddString("9,10");
	//m_jieshu.SetCurSel(0);

	m_jiaoxuelu.AddString("j1-");
	m_jiaoxuelu.AddString("j2-");
	m_jiaoxuelu.AddString("j3-");
	//m_jiaoxuelu.SetCurSel(0);

	m_jiaoshi.AddString("101");
	m_jiaoshi.AddString("102");
	m_jiaoshi.AddString("103");
	m_jiaoshi.AddString("104");
	m_jiaoshi.AddString("105");
	m_jiaoshi.AddString("106");
	m_jiaoshi.AddString("107");
	//m_jiaoshi.SetCurSel(0);
	
	return true;
}
void addkechengxinxiDlg::Onaddkechengxinxi() 
{
	UpdateData(TRUE); 
	m_cno.TrimLeft();
	m_cno.TrimRight();
	if(	m_cno.GetLength()<1)
	{
		AfxMessageBox("课程编号不能为空!");
		return;
	}
	m_cname.TrimLeft();
	m_cname.TrimRight();
	if(	m_cname.GetLength()<1) 
	{
		AfxMessageBox("课程名称不能为空!");
		return;
	}
	
	m_cteacher_no.TrimLeft();
	m_cteacher_no.TrimRight();
	if(	m_cteacher_no.GetLength()<1) 
	{
		AfxMessageBox("任课教师编号不能为空!");
		return;
	}

	CString str1,str2,str3,str4,str5,str6,str7,str31,str32,str41,str42;
	str1=m_cno;
	str2=m_cname;
    int index31=m_xingqi.GetCurSel();
	m_xingqi.GetLBText(index31,str31);
	if(str31=="")
	{
		AfxMessageBox("请选择星期!");
		return;
	}
	int index32=m_jieshu.GetCurSel();
	m_jieshu.GetLBText(index32,str32);
	if(str32=="")
	{
		AfxMessageBox("请选择节数!");
		return;
	}
	str3=str31+str32;
	int index41=m_jiaoxuelu.GetCurSel();
	m_jiaoxuelu.GetLBText(index41,str41);
	if(str41=="")
	{
		AfxMessageBox("请选择教学楼!");
		return;
	}
	str41.TrimLeft();
	str41.TrimRight();
    int index42=m_jiaoshi.GetCurSel();
	m_jiaoshi.GetLBText(index42,str42);
	str42.TrimLeft();
	str42.TrimRight();
	if(str42=="")
	{
		AfxMessageBox("请选择教师!");
		return;
	}
	str4=str41+str42;
	str5=m_cteacher_no;
	str6="insert into C_info VALUES('"+str1+"','"+str2+"','"+str5+"')";
	str7="insert into CT_info VALUES('"+str1+"','"+str3+"','"+str4+"')";
	CString str8="SELECT * FROM CT_info where C_time='"+str3+"' and C_place='"+str4+"' ";
	m_ktprecordset=new KT_infodb(m_pdb);
    m_ktprecordset->Open(KT_infodb::snapshot,str8);
    if(!m_ktprecordset->IsEOF())
	{
		AfxMessageBox("该教室在此时间已被占用,请重新选择开课时间或教室!");
		return;
	}


	CString str9="SELECT * FROM T_info where T_no='"+str5+"' ";
	m_pdeprecordset=new T_infodb(m_pdb);
    m_pdeprecordset->Open(T_infodb::snapshot,str9);
    if(m_pdeprecordset->IsEOF())
	{
		AfxMessageBox("没有此编号的教师,请重新输入教师编号!");
		this->GetDlgItem(IDC_EDIT5)->SetWindowText("");
		return;
	}
    else
	{
		CString str="SELECT * FROM C_info where C_no='"+str1+"' ";
	    m_precordset=new kecheng_infodb(m_pdb);
        m_precordset->Open(kecheng_infodb::snapshot,str);
		CString  Tc_no,c_name,t_no;
		c_name=m_precordset->m_C_name;
		t_no=m_precordset->m_T_no;
        if(!m_precordset->IsEOF())
		{
		    
			CString str="SELECT * FROM CT_info where C_no='"+str1+"' and C_time='"+str3+"' ";
	        m_ktprecordset=new KT_infodb(m_pdb);
            m_ktprecordset->Open(KT_infodb::snapshot,str);
	        if(!m_ktprecordset->IsEOF())
			{
			  AfxMessageBox("此课在此时间已经安排了!");
			  return;
			}

	        else   
			{
			  CString str9="SELECT * FROM C_info where T_no='"+str5+"' ";
              
	          m_precordset=new kecheng_infodb(m_pdb);
              m_precordset->Open(kecheng_infodb::snapshot,str9);	
		
		      
	          if(!m_precordset->IsEOF())
			  { 
				  m_precordset->MoveFirst();
	              while(!m_precordset->IsEOF())	
				  { 
					  Tc_no=m_precordset->m_C_no;
					  CString str10="SELECT * FROM CT_info where C_no='"+Tc_no+"' and C_time='"+str3+"' ";
	                  m_ktprecordset=new KT_infodb(m_pdb);
                      m_ktprecordset->Open(KT_infodb::snapshot,str10);		 		              
		              if(!m_ktprecordset->IsEOF())
					  {
						  AfxMessageBox("老师在此时间已有课程,请重新选择开课时间!");
			              return;
					  }
					  m_precordset->MoveNext();
				  }			   			      		          
			  }			  
			}
			if(t_no.Left(3)!=str5.Left(3))
			{
				AfxMessageBox("此课程不是该老师所开,开课老师编号应该为:"+t_no);
				this->GetDlgItem(IDC_EDIT5)->SetWindowText(t_no);
				return;

			}
			//if(c_name.Left(!=str2)
			//{
			//	AfxMessageBox("此课程名不对,应该为:"+c_name);
			//	this->GetDlgItem(IDC_EDIT2)->SetWindowText(c_name);
			//	return;
			//}
			 m_pdb->ExecuteSQL(str7);
			 AfxMessageBox("添加成功!");	
	
	         this->GetDlgItem(IDC_EDIT1)->SetWindowText("");
	         this->GetDlgItem(IDC_EDIT2)->SetWindowText("");
	         this->GetDlgItem(IDC_EDIT5)->SetWindowText(""); 
		}
	   else
	   {
		   CString str9="SELECT * FROM C_info where T_no='"+str5+"' ";
           CString  Tc_no;
	       m_precordset=new kecheng_infodb(m_pdb);
           m_precordset->Open(kecheng_infodb::snapshot,str9);	
		
		
	       if(!m_precordset->IsEOF())
		   { 
				m_precordset->MoveFirst();
	            while(!m_precordset->IsEOF())	
				 { 
					  Tc_no=m_precordset->m_C_no;
					  CString str10="SELECT * FROM CT_info where C_no='"+Tc_no+"' and C_time='"+str3+"' ";
	                  m_ktprecordset=new KT_infodb(m_pdb);
                      m_ktprecordset->Open(KT_infodb::snapshot,str10);		 		              
		              if(!m_ktprecordset->IsEOF())
					  {
						  AfxMessageBox("老师在此时间已有课程,请重新选择开课时间!");
			              return;
					  }
					  m_precordset->MoveNext();
				 }			   			      		          
			}			  
      
		
	       m_pdb->ExecuteSQL(str6);
	       m_pdb->ExecuteSQL(str7);
	       AfxMessageBox("添加成功!");	
	
	       this->GetDlgItem(IDC_EDIT1)->SetWindowText("");
           this->GetDlgItem(IDC_EDIT2)->SetWindowText("");
	       this->GetDlgItem(IDC_EDIT5)->SetWindowText(""); 
	   }
	}
}

void addkechengxinxiDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void addkechengxinxiDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	//dc.SetBkMode(OPAQUE);
	//dc.SetBkColor(RGB(255,0,0));
	// TODO: Add your message handler code here
	
	// Do not call CDialog::OnPaint() for painting messages
}

void addkechengxinxiDlg::OnKillfocusCombo1() 
{
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -