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

📄 addcontact.cpp

📁 自已做的简单的库存管理软件。包含员工信息管理等
💻 CPP
字号:
// AddContact.cpp : 实现文件
//

#include "stdafx.h"
#include "AddContact.h"


extern CString str_customername;
extern _ConnectionPtr pMyConnect;
// CAddContact 对话框

IMPLEMENT_DYNAMIC(CAddContact, CDialog)

CAddContact::CAddContact(CWnd* pParent /*=NULL*/)
	: CDialog(CAddContact::IDD, pParent)
{

}

CAddContact::~CAddContact()
{
}

void CAddContact::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CAddContact, CDialog)
	ON_BN_CLICKED(IDOK, &CAddContact::OnBnClickedOk)
END_MESSAGE_MAP()


// CAddContact 消息处理程序


BOOL CAddContact::OnInitDialog()
{
	CDialog::OnInitDialog();

	CWnd *pWnd;
	pWnd = GetDlgItem(IDC_EDIT_CUSTOMER);
	pWnd->SetWindowTextW(str_customername);

	ResetCombo();

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}


void CAddContact::ResetCombo()
{

	CComboBox* pWnd;
	pWnd = (CComboBox*)GetDlgItem(IDC_COMBO_SEX);
	pWnd->ResetContent();

	pWnd->AddString( _T("男")  );
	pWnd->AddString( _T("女")  );

}
void CAddContact::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码

	_RecordsetPtr m_pRs; 
	CString m_strSql; 	

	CWnd* pWnd;

	CString str_contact;
	pWnd = GetDlgItem(IDC_EDIT_CONTACT);
	pWnd->GetWindowText(str_contact);
	if ( str_contact.GetLength() == 0 )
	{
		AfxMessageBox(_T("联系人姓名不能为空!"));
		return;
	}
	if ( str_contact.GetLength() > 20 )
	{
		AfxMessageBox(_T("联系人姓名长度超出限制!"));
		return;
	}

	CString str_customersn = _T("");
	m_strSql.Format(_T("select SN from CUSTOMER_TABLE where ( NAME ='") +str_customername+ _T("')") ); 
	m_pRs.CreateInstance( __uuidof(Recordset) ); 
	m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);
	
	try
	{
		if ( m_pRs->GetRecordCount() > 0 )
		{
			_variant_t   TheValue;
			m_pRs->MoveFirst(); 
			while(m_pRs->adoEOF==VARIANT_FALSE)	
			{
				//Retrieve column's value: 	 
				TheValue = m_pRs->Fields->GetItem(_variant_t("SN"))->Value;		
				if( TheValue.vt != VT_NULL )
				{
					_bstr_t s1=(_bstr_t)TheValue; 
					CString str_temp = s1;
					str_customersn = str_temp;
				}
				
				//Do something what you want to do:	......
				m_pRs->MoveNext(); 
			}		
		}
	}
	catch (_com_error &e)
	{
		::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
	}
	m_pRs->Close(); 


	bool bHad = FALSE;
	m_strSql.Format(_T("select SN from CUSTOMER_CONTACT_TABLE where ( CONTACT_NAME ='") +str_contact+ _T("' and CUSTOMER_SN='") +str_customersn+ _T("')") ); 
	m_pRs.CreateInstance( __uuidof(Recordset) ); 
	m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);
	
	try
	{
		if ( m_pRs->GetRecordCount() > 0 )
		{
			_variant_t   TheValue;
			m_pRs->MoveFirst(); 
			while(m_pRs->adoEOF==VARIANT_FALSE)	
			{
				//Retrieve column's value: 	   
				TheValue = m_pRs->Fields->GetItem(_variant_t("SN"))->Value;				
				
				if( TheValue.vt != VT_NULL )
				{
					_bstr_t s1=(_bstr_t)TheValue; 
					bHad = TRUE;
				}
				//Do something what you want to do:	......
				m_pRs->MoveNext(); 
			}		
		}
	}
	catch (_com_error &e)
	{
		::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
	}
	m_pRs->Close(); 
	if( bHad )
	{
		AfxMessageBox(_T("此联系人已经存在!"));
		return;
	}

	CString str_post;
	pWnd = GetDlgItem(IDC_EDIT_POST);
	pWnd->GetWindowText(str_post);
	if ( str_post.GetLength() == 0 )
	{
		AfxMessageBox(_T("联系人职位不能为空!"));
		return;
	}
	if ( str_post.GetLength() > 20 )
	{
		AfxMessageBox(_T("联系人职位长度超出限制!"));
		return;
	}

	CString str_sex;
	pWnd = GetDlgItem(IDC_COMBO_SEX);
	pWnd->GetWindowText(str_sex);
	if ( str_sex.GetLength() == 0 )
	{
		AfxMessageBox(_T("请选择联系人性别!"));
		return;
	}


	
	CString str_tel;
	pWnd = GetDlgItem(IDC_EDIT_TEL);
	pWnd->GetWindowText(str_tel);
	if ( str_tel.GetLength() == 0 )
	{
		AfxMessageBox(_T("联系人电话不能为空!"));
		return;
	}
	if ( str_tel.GetLength() > 20 )
	{
		AfxMessageBox(_T("联系人电话长度超出限制!"));
		return;
	}

	CString str_mobile;
	pWnd = GetDlgItem(IDC_EDIT_MOBILE);
	pWnd->GetWindowText(str_mobile);
	if ( str_mobile.GetLength() == 0 )
	{
		AfxMessageBox(_T("联系人手机不能为空!"));
		return;
	}
	if ( str_mobile.GetLength() > 20 )
	{
		AfxMessageBox(_T("联系人手机长度超出限制!"));
		return;
	}

	CString str_fax;
	pWnd = GetDlgItem(IDC_EDIT_FAX);
	pWnd->GetWindowText(str_fax);
	if ( str_fax.GetLength() == 0 )
	{
		AfxMessageBox(_T("联系人传真不能为空!"));
		return;
	}
	if ( str_fax.GetLength() > 20 )
	{
		AfxMessageBox(_T("联系人传真长度超出限制!"));
		return;
	}

	CString str_email;
	pWnd = GetDlgItem(IDC_EDIT_EMAIL);
	pWnd->GetWindowText(str_email);
	if ( str_email.GetLength() == 0 )
	{
		AfxMessageBox(_T("联系人电邮不能为空!"));
		return;
	}
	if ( str_email.GetLength() > 50 )
	{
		AfxMessageBox(_T("联系人电邮长度超出限制!"));
		return;
	}

	

	CString str_note;
	pWnd = GetDlgItem(IDC_EDIT_NOTE);
	pWnd->GetWindowText(str_note);
	if ( str_note.GetLength() > 50 )
	{
		AfxMessageBox(_T("联系人地址长度超出限制!"));
		return;
	}

	


	_variant_t RecordsAffected;

	m_strSql.Format(_T("INSERT INTO CUSTOMER_CONTACT_TABLE(CUSTOMER_SN,CONTACT_NAME,POST,SEX,TEL,MOBILE,FAX,EMAIL,NOTE) VALUES ('") 
		+str_customersn+ _T("','") +str_contact+ _T("','") +str_post+ _T("','") +str_sex+ _T("','")  +str_tel+ _T("','") +str_mobile+ _T("','") +str_fax+ _T("','") +str_email+ 
		_T("','") +str_note+ _T("')"));
		
	bool bSuccess = pMyConnect->Execute(_bstr_t(m_strSql),&RecordsAffected,adCmdText);
	if( !bSuccess )
	{
		AfxMessageBox(_T("增加联系人信息失败,请重启系统!"));
		return;
	}
	AfxMessageBox(_T("增加联系人信息成功!"));
	

	OnOK();
}

⌨️ 快捷键说明

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