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

📄 typeadddlg.cpp

📁 自己编写的迷你图书馆的完整程序.VC6MFC编写的,Windows界面.数据采用了Sqlserver2000.压缩包中已包括了数据库.先附加数据库再运行.
💻 CPP
字号:
// TypeAddDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BookLib.h"
#include "TypeAddDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTypeAddDlg dialog


CTypeAddDlg::CTypeAddDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTypeAddDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTypeAddDlg)
	m_typename = _T("");
	m_subname = _T("");
	m_typecode = _T("");
	m_subcode = _T("");
	m_charge = _T("");
	m_place = _T("");
	//}}AFX_DATA_INIT
}


void CTypeAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTypeAddDlg)
	DDX_Text(pDX, IDC_EDIT_TYPENAME, m_typename);
	DDV_MaxChars(pDX, m_typename, 20);
	DDX_Text(pDX, IDC_EDIT_SUBTYPE, m_subname);
	DDX_Text(pDX, IDC_EDIT_TYPECODE, m_typecode);
	DDV_MaxChars(pDX, m_typecode, 20);
	DDX_Text(pDX, IDC_EDIT_SUBCODE, m_subcode);
	DDV_MaxChars(pDX, m_subcode, 20);
	DDX_Text(pDX, IDC_EDIT_CHARGE, m_charge);
	DDV_MaxChars(pDX, m_charge, 20);
	DDX_Text(pDX, IDC_EDIT_PLACE, m_place);
	DDV_MaxChars(pDX, m_place, 20);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTypeAddDlg, CDialog)
	//{{AFX_MSG_MAP(CTypeAddDlg)
	ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTypeAddDlg message handlers

void CTypeAddDlg::OnBtnAdd() 
{
	if(!UpdateData()) return;
	if(m_typename.IsEmpty())
	{
		MessageBox("请输入类别名称!","错误");
		return;
	}
	if(m_typecode.IsEmpty())
	{
		MessageBox("请输入类别代码!","错误");
		return;
	}
	if(m_subname.IsEmpty())
	{
		MessageBox("请输入子类别名称!","错误");
		return;
	}
	if(m_subcode.IsEmpty())
	{
		MessageBox("请输入子类代码!","错误");
		return;
	}
	if(m_place.IsEmpty())
	{
		MessageBox("请输入存放位置!","错误");
		return;
	}
	if(m_charge.IsEmpty())
	{
		MessageBox("请输入负责人!","错误");
		return;
	}

	CString sql,strTypeCode;
	sql.Format("select 类别代码 from 书籍类别表 where 类别名称='%s'",m_typename);
	g_adoDB.ExecuteQueryValue(sql,strTypeCode);
	if(!strTypeCode.IsEmpty())
	{
		if(strTypeCode!=m_typecode)
		{
			MessageBox("类别名称已经存在,但输入代码与现有不一致!","错误");
			return;
		}else{
			sql.Format("select 子类名称 from 书籍类别表 where 子类名称='%s'",m_subname);
			CString strSubName;
			g_adoDB.ExecuteQueryValue(sql,strSubName);
			if(!strSubName.IsEmpty())
			{
				MessageBox("(类别名称,子类名称)已经存在!","错误");
				return;
			}
		}
	}else{
		sql.Format("select 类别代码 from 书籍类别表 where 类别代码='%s'",m_typecode);
		g_adoDB.ExecuteQueryValue(sql,strTypeCode);
		if(!strTypeCode.IsEmpty())
		{
			MessageBox("该类别代码已经存在!","错误");
			return;
		}
	}

	CString strID;
	g_adoDB.ExecuteQueryValue("Select max(typeID) from 书籍类别表",strID);
	int newID=atoi(strID)+1;
	sql.Format("Insert into 书籍类别表 values(%d,'%s','%s','%s','%s','%s','%s')"
		,newID,m_typename,m_typecode,m_subname,m_subcode,m_place,m_charge);
	g_adoDB.Execute(sql);
	
	OnCancel();
	
}

⌨️ 快捷键说明

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