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

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


// AddPost 对话框

IMPLEMENT_DYNAMIC(AddPost, CDialogEx)

AddPost::AddPost(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_ADD_POST, pParent)
	, PostID(_T(""))
	, PostName(_T(""))
{

}

AddPost::~AddPost()
{
}

void AddPost::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_POST_ID, PostID);
	DDX_Text(pDX, IDC_POST_NAME, PostName);
}


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


// AddPost 消息处理程序


void AddPost::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	char* order = new char[STR_NUM];
	int postID = CZGKJApp::MyTtoI(PostID);
	const char* postName = CZGKJApp::MyTtoA(PostName);
	sprintf_s(order, STR_NUM - 1, "INSERT INTO tb_post (post_id,post_name)VALUES (%d,'%s')", postID, postName);
	if (theApp.sql->ExecutiveCommand(order))
	{
		CString error = CZGKJApp::MyAtoT(theApp.sql->GetErrorInformation());
		AfxMessageBox(error, MB_OK | MB_ICONERROR);
		return;
	}
	AfxMessageBox(_T("添加职务成功！"));
	CDialogEx::OnOK();
}
