193 lines
3.7 KiB
C++
193 lines
3.7 KiB
C++
#include "stdafx.h"
|
|
#include "ZHDLDlg.h"
|
|
#include "LJCSDlg.h"
|
|
#include "uiiado.h"
|
|
|
|
extern BOOL GetLocalIP(CStringArray& arsIP);
|
|
|
|
IMPLEMENT_DYNAMIC(CZHDLDlg, CDialog)
|
|
|
|
CZHDLDlg::CZHDLDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CZHDLDlg::IDD, pParent)
|
|
, m_sName(_T(""))
|
|
, m_sProName(_T(""))
|
|
, m_sPartMt(_T(""))
|
|
, m_sIP(_T(""))
|
|
, m_sPassword(_T(""))
|
|
, m_sPassword2(_T(""))
|
|
{
|
|
m_pMySQLDb = NULL;
|
|
m_bCreate = FALSE;
|
|
|
|
// GET_CACHE(CZHDLDlg
|
|
// , %s%s%s%s
|
|
// , &m_sName
|
|
// , &m_sProName
|
|
// , &m_sPartMt
|
|
// , &m_sIP);
|
|
}
|
|
|
|
CZHDLDlg::~CZHDLDlg()
|
|
{
|
|
if (m_pMySQLDb != NULL)
|
|
delete m_pMySQLDb;
|
|
}
|
|
|
|
void CZHDLDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Text(pDX, IDC_EDIT6, m_sName);
|
|
DDX_CBString(pDX, IDC_COMBO2, m_sProName);
|
|
DDX_CBString(pDX, IDC_COMBO3, m_sIP);
|
|
DDX_Text(pDX, IDC_EDIT1, m_sPassword);
|
|
DDX_Text(pDX, IDC_EDIT4, m_sPassword2);
|
|
DDX_Control(pDX, IDC_COMBO3, m_wndIPCombox);
|
|
DDX_Control(pDX, IDC_COMBO1, m_wndDeptCombo);
|
|
DDX_CBString(pDX, IDC_COMBO1, m_sPartMt);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CZHDLDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CZHDLDlg::OnBnClickedOk)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CZHDLDlg::OnBnClickedButton1)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CZHDLDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
InitMeIPCombox();
|
|
|
|
if ( !InitADOServer() )
|
|
{
|
|
AfxMessageBox(_T("连接数据库服务器失败!请检查数据库测试连接!"));
|
|
return FALSE;
|
|
}
|
|
|
|
InitDeptCombox();
|
|
|
|
if (!m_bCreate)
|
|
{
|
|
GetDlgItem(IDC_BUTTON1)->ShowWindow(SW_HIDE);
|
|
GetDlgItem(IDC_EDIT4)->ShowWindow(SW_HIDE);
|
|
GetDlgItem(IDC_STATIC_SR)->ShowWindow(SW_HIDE);
|
|
}
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CZHDLDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData();
|
|
|
|
if (m_sName.IsEmpty() ||
|
|
m_sProName.IsEmpty() ||
|
|
m_sPartMt.IsEmpty() ||
|
|
m_sIP.IsEmpty() ||
|
|
m_sPassword.IsEmpty() )
|
|
{
|
|
AfxMessageBox(_T("请确认账户信息是否完整!"));
|
|
return;
|
|
}
|
|
|
|
CString sSQL;
|
|
sSQL.Format(_T("select Name from Aec_Employees where Name='%s' and Password='%s' and IP like '%s'"),m_sName,m_sPassword,m_sIP);
|
|
|
|
if (m_pMySQLDb->IsSelEmpty(sSQL))
|
|
{
|
|
AfxMessageBox(_T("登录失败,请检查账户名和密码!"));
|
|
return;
|
|
}
|
|
|
|
// SET_CACHE(CZHDLDlg
|
|
// , %s%s%s%s
|
|
// , &m_sName
|
|
// , &m_sProName
|
|
// , &m_sPartMt
|
|
// , &m_sIP);
|
|
|
|
OnOK();
|
|
}
|
|
|
|
void CZHDLDlg::OnBnClickedButton1()
|
|
{
|
|
UpdateData();
|
|
|
|
if (m_sName.IsEmpty() ||
|
|
m_sProName.IsEmpty() ||
|
|
m_sPartMt.IsEmpty() ||
|
|
m_sIP.IsEmpty() ||
|
|
m_sPassword.IsEmpty() )
|
|
{
|
|
AfxMessageBox(_T("请确认账户信息是否完整!"));
|
|
return;
|
|
}
|
|
|
|
if (m_sPassword.Compare(m_sPassword2) != 0)
|
|
{
|
|
AfxMessageBox(_T("请确认登陆密码是否一致!"));
|
|
return;
|
|
}
|
|
|
|
CString sSQL;
|
|
sSQL.Format(_T("select IP from Aec_Employees where IP like '%s'"),m_sIP);
|
|
if ( !m_pMySQLDb->IsSelEmpty(sSQL) )
|
|
{
|
|
AfxMessageBox(_T("IP对应的账户已经存在!"));
|
|
return;
|
|
}
|
|
|
|
sSQL.Format(_T("insert into Aec_Employees (IP,Name,Password,Pro,PartMt,Rem) values ('%s','%s','%s','%s','%s','%s')"),
|
|
m_sIPs,m_sName,m_sPassword,m_sProName,m_sPartMt,_T("-"));
|
|
|
|
if ( m_pMySQLDb->ExecuteSQL(sSQL) )
|
|
{
|
|
AfxMessageBox(_T("账户已经创建成功!"));
|
|
EndDialog(IDOK);
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("账户创建失败!"));
|
|
}
|
|
}
|
|
|
|
void CZHDLDlg::InitDeptCombox()
|
|
{
|
|
CString sSQL;
|
|
sSQL = _T("select distinct PartMt from Aec_Employees");
|
|
|
|
CStringArray arVals;
|
|
m_pMySQLDb->GetSelData(sSQL,arVals);
|
|
|
|
for (int i = 0;i < arVals.GetSize();i++)
|
|
{
|
|
m_wndDeptCombo.AddString(arVals.GetAt(i));
|
|
}
|
|
}
|
|
|
|
void CZHDLDlg::InitMeIPCombox()
|
|
{
|
|
CStringArray arIps;
|
|
GetLocalIP(arIps);
|
|
|
|
for (int i = 0;i < arIps.GetSize();i++)
|
|
{
|
|
m_wndIPCombox.AddString(arIps.GetAt(i));
|
|
m_sIPs += arIps.GetAt(i);
|
|
m_sIPs += _T(",");
|
|
}
|
|
m_sIPs.TrimRight(_T(","));
|
|
|
|
if (arIps.GetSize() > 0)
|
|
{
|
|
m_wndIPCombox.SetCurSel(0);
|
|
m_sIP = arIps.GetAt(0);
|
|
}
|
|
}
|
|
|
|
BOOL CZHDLDlg::InitADOServer()
|
|
{
|
|
m_pMySQLDb = CLJCSDlg::GetSHEarthWormConnect();
|
|
return (m_pMySQLDb != NULL) ? TRUE : FALSE;
|
|
} |