// AddDep.cpp: 实现文件
//

#include "pch.h"
#include "ZGKJ.h"
#include "afxdialogex.h"
#include "AddDep.h"


// AddDep 对话框

IMPLEMENT_DYNAMIC(AddDep, CDialogEx)

AddDep::AddDep(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_ADD_DEP, pParent)
	, DepId(_T(""))
	, DepName(_T(""))
{

}

AddDep::~AddDep()
{
}

void AddDep::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_DEP_ID, DepId);
	DDX_Text(pDX, IDC_DEP_NAME, DepName);
}


BEGIN_MESSAGE_MAP(AddDep, CDialogEx)
	ON_BN_CLICKED(IDOK, &AddDep::OnBnClickedOk)
END_MESSAGE_MAP()


// AddDep 消息处理程序


void AddDep::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	char* order = new char[STR_NUM];
	int depID = CZGKJApp::MyTtoI(DepId);
	const char* depName = CZGKJApp::MyTtoA(DepName);
	sprintf_s(order, STR_NUM - 1, "INSERT INTO tb_department (department_id,department_name)VALUES (%d,'%s')", depID, depName);
	if (theApp.sql->ExecutiveCommand(order))
	{
		CString error = CZGKJApp::MyAtoT(theApp.sql->GetErrorInformation());
		AfxMessageBox(error, MB_OK | MB_ICONERROR);
		return;
	}
	AfxMessageBox(_T("添加部门成功！"));
	delete[] order;
	CDialogEx::OnOK();
}
