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

📄 changebrand.cpp

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

#include "stdafx.h"
#include "ChangeBrand.h"

extern _ConnectionPtr pMyConnect;
extern bool bAdd;
extern int index;
extern CString str_data[10][8];


// CChangeBrand dialog

IMPLEMENT_DYNAMIC(CChangeBrand, CDialog)

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

}

CChangeBrand::~CChangeBrand()
{
}

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


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


// CChangeBrand message handlers


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

	
	if (bAdd)
	{
		SetWindowText(_T("增加品牌"));
	}
	else
	{
		SetWindowText(_T("修改品牌"));

		CWnd* pWnd;
		pWnd = GetDlgItem(IDC_EDIT_BRAND);
		pWnd->SetWindowText(str_data[index][0]);
		pWnd->EnableWindow(FALSE);

		pWnd = GetDlgItem(IDC_EDIT_NAME);
		pWnd->SetWindowText(str_data[index][1]);

		pWnd = GetDlgItem(IDC_EDIT_TEL);
		pWnd->SetWindowText(str_data[index][2]);

		pWnd = GetDlgItem(IDC_EDIT_FAX);
		pWnd->SetWindowText(str_data[index][3]);

		pWnd = GetDlgItem(IDC_EDIT_EMAIL);
		pWnd->SetWindowText(str_data[index][4]);

		pWnd = GetDlgItem(IDC_EDIT_WEBSITE);
		pWnd->SetWindowText(str_data[index][5]);

	}
	return FALSE;// 将焦点设置到控件,否则返回 TRUE
}
void CChangeBrand::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	
	CString str0;
	CString str1;
	CString str2;
	CString str3;
	CString str4;
	CString str5;
	CString str6 = str_data[index][6];

	CWnd* pWnd;
		
	
	//BRAND
	pWnd = GetDlgItem(IDC_EDIT_BRAND);
	pWnd->GetWindowText(str0);
	if ( str0.GetLength() == 0 )
	{
		AfxMessageBox(_T("品牌不能为空!"));
		return;
	}
	if ( str0.GetLength() > 20 )
	{
		AfxMessageBox(_T("品牌长度超出限制!"));
		return;
	}
	
	_RecordsetPtr m_pRs; 
	CString m_strSql; 

	if (bAdd)
	{
		bool bHad = FALSE;
		m_strSql.Format(_T("select SN from BRAND_TABLE where ( BRAND='") + str0 +  _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 )
			{
				m_pRs->MoveFirst(); 
				while(m_pRs->adoEOF==VARIANT_FALSE)	
				{
					//Retrieve column's value: 	   
					
					_variant_t   TheValue;
					TheValue = m_pRs->Fields->GetItem(_variant_t("SN"))->Value;
					if(TheValue.vt   != VT_NULL)
					{
						_bstr_t s1=(_bstr_t)TheValue; 
						
						CString sn = s1;
						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;
		}
	}
		
	//COMPANY
	pWnd = GetDlgItem(IDC_EDIT_NAME);
	pWnd->GetWindowText(str1);	
	if ( str1.GetLength() == 0 )
	{
		AfxMessageBox(_T("名称不能为空!"));
		return;
	}
	if ( str1.GetLength() > 50 )
	{
		AfxMessageBox(_T("名称长度超出限制!"));
		return;
	}
	
	//TEL
	pWnd = GetDlgItem(IDC_EDIT_TEL);
	pWnd->GetWindowText(str2);	
	if ( str2.GetLength() == 0 )
	{
		AfxMessageBox(_T("电话不能为空!"));
		return;
	}
	if ( str2.GetLength() > 20 )
	{
		AfxMessageBox(_T("电话长度超出限制!"));
		return;
	}
	
	//FAX
	pWnd = GetDlgItem(IDC_EDIT_FAX);
	pWnd->GetWindowText(str3);
	if ( str3.GetLength() == 0 )
	{
		AfxMessageBox(_T("传真不能为空!"));
		return;
	}
	if ( str3.GetLength() > 20 )
	{
		AfxMessageBox(_T("传真长度超出限制!"));
		return;
	}

	//EMAIL
	pWnd = GetDlgItem(IDC_EDIT_EMAIL);
	pWnd->GetWindowText(str4);	
	if ( str4.GetLength() == 0 )
	{
		AfxMessageBox(_T("电邮不能为空!"));
		return;
	}
	if ( str4.GetLength() > 30 )
	{
		AfxMessageBox(_T("电邮长度超出限制!"));
		return;
	}

	//WEBSITE
	pWnd = GetDlgItem(IDC_EDIT_WEBSITE);
	pWnd->GetWindowText(str5);	
	if ( str5.GetLength() == 0 )
	{
		AfxMessageBox(_T("网址不能为空!"));
		return;
	}
	if ( str5.GetLength() > 30 )
	{
		AfxMessageBox(_T("网址长度超出限制!"));
		return;
	}


	//goto the last page, and then add a item
	//CString m_strSql; 
	_RecordsetPtr m_pRecordset;
	_variant_t RecordsAffected;
	bool bSuccess;

	if (bAdd)
	{
		
		m_strSql.Format(_T("INSERT INTO BRAND_TABLE(BRAND,COMPANY,TEL,FAX,EMAIL,WEBSITE) VALUES ('") +str0+ _T("','") +str1+ _T("','") +str2+ _T("','") +str3+ _T("','") +str4+ _T("','") +str5+ _T("')"));
		bSuccess = pMyConnect->Execute(_bstr_t(m_strSql),&RecordsAffected,adCmdText);
		if( !bSuccess )
		{
			AfxMessageBox(_T("增加品牌失败,请重启系统!"));
			return;
		}
		AfxMessageBox(_T("增加品牌成功!"));

	}
	else
	{
		m_strSql.Format(_T("update BRAND_TABLE set BRAND='") +str0+ _T("',COMPANY='") +str1+ _T("',TEL='") +str2+ _T("',FAX='") +str3+ _T("',EMAIL='") +str4+ _T("',WEBSITE='") +str5+ _T("' where( SN=") +str6+ _T(")") );
		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 + -